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

fix(editor): trigger height adjustment on paste to textarea #4520

Merged
merged 1 commit into from
Jun 6, 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: 8 additions & 0 deletions src/components/Editor/Article/Summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ const EditorSummary: React.FC<Props> = ({
}
}

const handlePaste = () => {
// FIXME: triggers the height adjustment on paste
setTimeout(() => {
autosize.update(instance.current)
})
}

React.useEffect(() => {
if (enable && instance) {
autosize(instance.current)
Expand Down Expand Up @@ -86,6 +93,7 @@ const EditorSummary: React.FC<Props> = ({
id: '16zJ3o',
})}
value={value}
onPaste={handlePaste}
onBlur={handleBlur}
onChange={handleChange}
onKeyDown={handleKeyDown}
Expand Down
12 changes: 11 additions & 1 deletion src/components/Editor/Article/Title/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const EditorTitle: React.FC<Props> = ({ defaultValue = '', update }) => {
}, INPUT_DEBOUNCE)

const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
const title = event.target.value.slice(0, MAX_ARTICE_TITLE_LENGTH)
const title = event.target.value
.replace(/\r\n|\r|\n/g, '')
.slice(0, MAX_ARTICE_TITLE_LENGTH)
setValue(title)
debouncedUpdate()
}
Expand All @@ -37,6 +39,13 @@ const EditorTitle: React.FC<Props> = ({ defaultValue = '', update }) => {
}
}

const handlePaste = () => {
// FIXME: triggers the height adjustment on paste
setTimeout(() => {
autosize.update(instance.current)
})
}

React.useEffect(() => {
if (instance) {
autosize(instance.current)
Expand All @@ -57,6 +66,7 @@ const EditorTitle: React.FC<Props> = ({ defaultValue = '', update }) => {
id: '//QMqf',
})}
value={value}
onPaste={handlePaste}
onChange={handleChange}
onBlur={handleBlur}
onKeyDown={handleKeyDown}
Expand Down
Loading