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

Teacher tool: notes area auto resizing on enter, more text entered #9920

Merged
merged 6 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 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 = `${25 + 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/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} autoResize={true} onChange={onChangeDebounce} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since DebouncedTextareaProps extends TextareaProps, someone can actually set autoResize when specifying a DebouncedTextarea component (i.e. <DebouncedTextarea autoResize={true} ... />), which I think is a good thing.

So instead of hardcoding this to true for all DebouncedTextAreas, could we let it pass-through as a part of the {...props} and just set autoResize to true in the Notes component?

};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
padding-bottom: 0.5rem;
margin-top: 0.5rem;
min-height: 9rem;
max-height: 12rem;
border-bottom: solid 1px var(--pxt-content-accent) ;
}

Expand All @@ -39,7 +38,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
1 change: 0 additions & 1 deletion teachertool/src/style.overrides/Textarea.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.common-textarea-wrapper {
div[class*="common-textarea-group"] {
border-radius: 0.5rem;
height: 3.5rem;
font-weight: 500;
&:focus::after {
outline: none;
Expand Down