Skip to content

Commit

Permalink
Merge pull request #4520 from thematters/fix/quote
Browse files Browse the repository at this point in the history
fix(editor): trigger height adjustment on paste to textarea
  • Loading branch information
robertu7 authored Jun 6, 2024
2 parents 112ae0a + 2ce7513 commit 59a2fa0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit 59a2fa0

Please sign in to comment.