Skip to content

Commit

Permalink
Teacher tool: notes area auto resizing on enter, more text entered (#…
Browse files Browse the repository at this point in the history
…9920)

* notes area auto resizing on enter, more text entered

* do not need a resize observer in debouncedtextarea

* remove ref as a prop, using use ref in textarea instead

* moved autoresize to criteriaresultsnotes, when initializing debouncedtextarea for notes

* more accurate resizing, got rid of unneeded padding
  • Loading branch information
srietkerk authored Mar 20, 2024
1 parent 21be101 commit e62d76c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions react-common/components/controls/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface TextareaProps extends ControlProps {
readOnly?: boolean;
resize?: "both" | "horizontal" | "vertical";
wrap?: "hard" | "soft" | "off";
autoResize?: boolean;

onChange?: (newValue: string) => void;
onEnterKey?: (value: string) => void;
Expand All @@ -38,11 +39,13 @@ export const Textarea = (props: TextareaProps) => {
readOnly,
resize,
wrap,
autoResize,
onChange,
onEnterKey
} = props;

const [value, setValue] = React.useState(initialValue || "");
const textareaRef = React.useRef<HTMLTextAreaElement>(null);

React.useEffect(() => {
setValue(initialValue)
Expand All @@ -57,6 +60,10 @@ export const Textarea = (props: TextareaProps) => {
if (onChange) {
onChange(newValue);
}
if (autoResize && textareaRef.current) {
textareaRef.current.style.height = "1px";
textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;
}
}

const enterKeyHandler = (e: React.KeyboardEvent) => {
Expand Down Expand Up @@ -90,6 +97,7 @@ export const Textarea = (props: TextareaProps) => {
minLength={minLength}
wrap={wrap}
readOnly={!!readOnly}
ref={textareaRef}
onChange={changeHandler}
onKeyDown={enterKeyHandler}
autoComplete={autoComplete ? "" : "off"}
Expand Down
2 changes: 1 addition & 1 deletion teachertool/src/components/CriteriaResultEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const CriteriaResultNotes: React.FC<CriteriaResultNotesProps> = ({ criteriaId, n
label={lf("Feedback")}
title={lf("Write your notes here")}
initialValue={teacherTool.evalResults[criteriaId]?.notes ?? undefined}
resize="vertical"
autoResize={true}
onChange={onTextChange}
autoComplete={false}
intervalMs={500}
Expand Down
2 changes: 1 addition & 1 deletion teachertool/src/components/DebouncedTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ export const DebouncedTextarea: React.FC<DebouncedTextareaProps> = ({ intervalMs
timerId.current = setTimeout(sendChange, intervalMs);
};

return <Textarea {...props} onChange={onChangeDebounce} />;
return <Textarea {...props} onChange={onChangeDebounce} />
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
align-items: center;
justify-content: flex-end;
width: 100%;
height: 5.5rem;
min-height: 5.5rem;
margin-top: 0.25rem;

.notes-container {
Expand Down
2 changes: 1 addition & 1 deletion teachertool/src/style.overrides/Textarea.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.common-textarea-wrapper {
div[class*="common-textarea-group"] {
border-radius: 0.5rem;
height: 3.5rem;
min-height: 4.25rem;
font-weight: 500;
&:focus::after {
outline: none;
Expand Down

0 comments on commit e62d76c

Please sign in to comment.