feat(editable-title): move and scroll to the end (#15270)

This commit is contained in:
Yaozong Liu 2021-06-23 13:01:14 +08:00 committed by GitHub
parent c211f7df8e
commit f31d573561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -70,6 +70,13 @@ export default function EditableTitle({
useEffect(() => {
if (isEditing) {
contentRef.current.focus();
// move cursor and scroll to the end
if (contentRef.current.setSelectionRange) {
const { length } = contentRef.current.value;
contentRef.current.setSelectionRange(length, length);
contentRef.current.scrollLeft = contentRef.current.scrollWidth;
contentRef.current.scrollTop = contentRef.current.scrollHeight;
}
}
}, [isEditing]);