From c40f2e50a143e8b184f4440ba03bdb05442364f5 Mon Sep 17 00:00:00 2001 From: Xitang Date: Sat, 1 Jul 2023 16:56:13 -0700 Subject: [PATCH] Create BulletListTextareaFallback to work around issue #15 --- .../Resume/ResumePDF/common/index.tsx | 4 +- .../components/ResumeForm/Form/InputGroup.tsx | 109 +++++++++++++++++- 2 files changed, 107 insertions(+), 6 deletions(-) diff --git a/src/app/components/Resume/ResumePDF/common/index.tsx b/src/app/components/Resume/ResumePDF/common/index.tsx index 1199816..67608b2 100644 --- a/src/app/components/Resume/ResumePDF/common/index.tsx +++ b/src/app/components/Resume/ResumePDF/common/index.tsx @@ -85,8 +85,8 @@ export const ResumePDFBulletList = ({ }) => { return ( <> - {items.map((item) => ( - + {items.map((item, idx) => ( + {showBulletPoints && ( ({ ); }; +export const BulletListTextarea = ( + props: InputProps & { showBulletPoints?: boolean } +) => { + if (navigator.userAgent.includes("Firefox")) { + return ; + } + return ; +}; + /** - * BulletListTextarea is a textarea where each new line starts with a bullet point. + * BulletListTextareaGeneral is a textarea where each new line starts with a bullet point. * * In its core, it uses a div with contentEditable set to True. However, when * contentEditable is True, user can paste in any arbitrary html and it would @@ -90,7 +99,7 @@ export const Textarea = ({ * * Reference: https://stackoverflow.com/a/74998090/7699841 */ -export const BulletListTextarea = ({ +const BulletListTextareaGeneral = ({ label, labelClassName: wrapperClassName, name, @@ -100,7 +109,6 @@ export const BulletListTextarea = ({ showBulletPoints = true, }: InputProps & { showBulletPoints?: boolean }) => { const html = getHTMLFromBulletListStrings(bulletListStrings); - return ( ({ placeholder={placeholder} onChange={(e) => { if (e.type === "input") { - const { innerText } = e.currentTarget; + const { innerText } = e.currentTarget as HTMLDivElement; const newBulletListStrings = getBulletListStringsFromInnerText(innerText); onChange(name, newBulletListStrings); @@ -160,3 +168,96 @@ const getHTMLFromBulletListStrings = (bulletListStrings: string[]) => { return bulletListStrings.map((text) => `
${text}
`).join(""); }; + +/** + * BulletListTextareaFallback is a fallback for BulletListTextareaGeneral to work around + * content editable div issue in some browsers. For example, in Firefox, if user enters + * space in the content editable div at the end of line, Firefox returns it as a new + * line character \n instead of space in innerText. + */ +const BulletListTextareaFallback = ({ + label, + labelClassName, + name, + value: bulletListStrings = [], + placeholder, + onChange, + showBulletPoints = true, +}: InputProps & { showBulletPoints?: boolean }) => { + const textareaValue = getTextareaValueFromBulletListStrings( + bulletListStrings, + showBulletPoints + ); + + return ( +