diff --git a/src/Components/Facility/ConsultationDoctorNotes/index.tsx b/src/Components/Facility/ConsultationDoctorNotes/index.tsx index 8e39ee04e4e..c17ee3fb2db 100644 --- a/src/Components/Facility/ConsultationDoctorNotes/index.tsx +++ b/src/Components/Facility/ConsultationDoctorNotes/index.tsx @@ -1,7 +1,6 @@ import { useState } from "react"; import * as Notification from "../../../Utils/Notifications.js"; import Page from "../../Common/components/Page"; -import TextFormField from "../../Form/FormFields/TextFormField"; import ButtonV2 from "../../Common/components/ButtonV2"; import CareIcon from "../../../CAREUI/icons/CareIcon"; import { NonReadOnlyUsers } from "../../../Utils/AuthorizeFor"; @@ -13,6 +12,7 @@ import request from "../../../Utils/request/request.js"; import useQuery from "../../../Utils/request/useQuery.js"; import useKeyboardShortcut from "use-keyboard-shortcut"; import { isAppleDevice } from "../../../Utils/utils.js"; +import AutoExpandingTextInputFormField from "../../Form/FormFields/AutoExpandingTextInputFormField.js"; interface ConsultationDoctorNotesProps { patientId: string; @@ -120,12 +120,14 @@ const ConsultationDoctorNotes = (props: ConsultationDoctorNotesProps) => { />
- setNoteField(e.value)} className="grow" - type="text" errorClassName="hidden" placeholder="Type your Note" disabled={!patientActive} diff --git a/src/Components/Facility/PatientNotesSlideover.tsx b/src/Components/Facility/PatientNotesSlideover.tsx index 5ecf30cfcdf..2e231576eb2 100644 --- a/src/Components/Facility/PatientNotesSlideover.tsx +++ b/src/Components/Facility/PatientNotesSlideover.tsx @@ -3,7 +3,6 @@ import * as Notification from "../../Utils/Notifications.js"; import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; import CareIcon from "../../CAREUI/icons/CareIcon"; import { classNames, isAppleDevice } from "../../Utils/utils"; -import TextFormField from "../Form/FormFields/TextFormField"; import ButtonV2 from "../Common/components/ButtonV2"; import { make as Link } from "../Common/components/Link.bs"; import { useMessageListener } from "../../Common/hooks/useMessageListener"; @@ -12,6 +11,7 @@ import request from "../../Utils/request/request"; import routes from "../../Redux/api"; import { PatientNoteStateType } from "./models"; import useKeyboardShortcut from "use-keyboard-shortcut"; +import AutoExpandingTextInputFormField from "../Form/FormFields/AutoExpandingTextInputFormField.js"; interface PatientNotesProps { patientId: string; @@ -169,13 +169,14 @@ export default function PatientNotesSlideover(props: PatientNotesProps) { setReload={setReload} />
- setNoteField(e.value)} className="grow" - type="text" errorClassName="hidden" placeholder="Type your Note" disabled={!patientActive} diff --git a/src/Components/Form/FormFields/AutoExpandingTextInputFormField.tsx b/src/Components/Form/FormFields/AutoExpandingTextInputFormField.tsx new file mode 100644 index 00000000000..22707f133bc --- /dev/null +++ b/src/Components/Form/FormFields/AutoExpandingTextInputFormField.tsx @@ -0,0 +1,30 @@ +import React, { useEffect, useRef } from "react"; +import TextAreaFormField, { TextAreaFormFieldProps } from "./TextAreaFormField"; + +type AutoExpandingTextInputFormFieldProps = TextAreaFormFieldProps & { + maxHeight?: number; +}; + +const AutoExpandingTextInputFormField = ( + props: AutoExpandingTextInputFormFieldProps +) => { + const myref = useRef(null); + useEffect(() => { + if (myref.current == null) return; + const text = myref.current.textContent?.split("\n"); + const len = text?.length || 1; + // 46 is height of the textarea when there is only 1 line + // getting line height from window + const lineHeight = + window.getComputedStyle(myref.current).lineHeight.slice(0, -2) || "20"; + // added 26 for padding (20+26 = 46) + const height = + Math.min(len * parseInt(lineHeight), (props.maxHeight || 160) - 26) + 26; + // 160 is the max height of the textarea if not specified + myref.current.style.cssText = "height:" + height + "px"; + }); + + return ; +}; + +export default AutoExpandingTextInputFormField; diff --git a/src/Components/Form/FormFields/TextAreaFormField.tsx b/src/Components/Form/FormFields/TextAreaFormField.tsx index 23a7d025938..5c23bfec764 100644 --- a/src/Components/Form/FormFields/TextAreaFormField.tsx +++ b/src/Components/Form/FormFields/TextAreaFormField.tsx @@ -1,33 +1,44 @@ +import { forwardRef } from "react"; import FormField from "./FormField"; import { FormFieldBaseProps, useFormFieldPropsResolver } from "./Utils"; -type TextAreaFormFieldProps = FormFieldBaseProps & { +export type TextAreaFormFieldProps = FormFieldBaseProps & { placeholder?: string; value?: string | number; rows?: number; // prefixIcon?: React.ReactNode; // suffixIcon?: React.ReactNode; + onFocus?: (event: React.FocusEvent) => void; + onBlur?: (event: React.FocusEvent) => void; }; -const TextAreaFormField = ({ rows = 3, ...props }: TextAreaFormFieldProps) => { - const field = useFormFieldPropsResolver(props as any); - return ( - -