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

View File

@ -70,6 +70,13 @@ export default function EditableTitle({
useEffect(() => { useEffect(() => {
if (isEditing) { if (isEditing) {
contentRef.current.focus(); 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]); }, [isEditing]);