Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multi-line text input for Doctor Notes #6977

Merged
merged 18 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Components/Facility/ConsultationDoctorNotes/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -120,12 +120,14 @@ const ConsultationDoctorNotes = (props: ConsultationDoctorNotesProps) => {
/>

<div className="relative mx-4 flex items-center">
<TextFormField
<AutoExpandingTextInputFormField
id="doctor_consultation_notes"
maxHeight={160}
rows={1}
name="note"
value={noteField}
onChange={(e) => setNoteField(e.value)}
className="grow"
type="text"
errorClassName="hidden"
placeholder="Type your Note"
disabled={!patientActive}
Expand Down
7 changes: 4 additions & 3 deletions src/Components/Facility/PatientNotesSlideover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -169,13 +169,14 @@ export default function PatientNotesSlideover(props: PatientNotesProps) {
setReload={setReload}
/>
<div className="relative mx-4 flex items-center">
<TextFormField
<AutoExpandingTextInputFormField
id="doctor_notes_textarea"
maxHeight={160}
rows={1}
name="note"
value={noteField}
onChange={(e) => setNoteField(e.value)}
className="grow"
type="text"
errorClassName="hidden"
placeholder="Type your Note"
disabled={!patientActive}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<HTMLTextAreaElement>(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 <TextAreaFormField ref={myref} {...props} className="w-full" />;
};

export default AutoExpandingTextInputFormField;
53 changes: 32 additions & 21 deletions src/Components/Form/FormFields/TextAreaFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
import { forwardRef } from "react";
import FormField from "./FormField";
import { FormFieldBaseProps, useFormFieldPropsResolver } from "./Utils";

type TextAreaFormFieldProps = FormFieldBaseProps<string> & {
export type TextAreaFormFieldProps = FormFieldBaseProps<string> & {
placeholder?: string;
value?: string | number;
rows?: number;
// prefixIcon?: React.ReactNode;
// suffixIcon?: React.ReactNode;
onFocus?: (event: React.FocusEvent<HTMLTextAreaElement>) => void;
onBlur?: (event: React.FocusEvent<HTMLTextAreaElement>) => void;
};

const TextAreaFormField = ({ rows = 3, ...props }: TextAreaFormFieldProps) => {
const field = useFormFieldPropsResolver(props as any);
return (
<FormField field={field}>
<textarea
id={field.id}
disabled={field.disabled}
name={field.name}
value={field.value}
required={field.required}
onChange={(e) => field.handleChange(e.target.value)}
placeholder={props.placeholder}
rows={rows}
className={`cui-input-base resize-none ${
field.error && "border-danger-500"
}`}
/>
</FormField>
);
};
const TextAreaFormField = forwardRef(
(
{ rows = 3, ...props }: TextAreaFormFieldProps,
ref?: React.Ref<HTMLTextAreaElement>
) => {
const field = useFormFieldPropsResolver(props as any);
return (
<FormField field={field}>
<textarea
id={field.id}
ref={ref}
disabled={field.disabled}
name={field.name}
value={field.value}
required={field.required}
onChange={(e) => field.handleChange(e.target.value)}
placeholder={props.placeholder}
rows={rows}
className={`cui-input-base resize-none ${
field.error && "border-danger-500"
}`}
onFocus={props.onFocus}
onBlur={props.onBlur}
/>
</FormField>
);
}
);

export default TextAreaFormField;
Loading