fix: Focus reset on comment edit (#10932)

This commit is contained in:
Tom Moor
2025-12-16 08:33:10 -05:00
committed by GitHub
parent 206df6afd7
commit 6fb5ca0d7d

View File

@@ -83,6 +83,7 @@ function CommentForm({
const [forceRender, setForceRender] = React.useState(0);
const [inputFocused, setInputFocused] = React.useState(autoFocus);
const file = React.useRef<HTMLInputElement>(null);
const hasFocusedOnMount = React.useRef(false);
const theme = useTheme();
const { t } = useTranslation();
const { comments } = useStores();
@@ -251,8 +252,9 @@ function CommentForm({
// Focus the editor when it's a new comment just mounted
const handleMounted = React.useCallback(
(ref) => {
if (autoFocus) {
ref?.focusAtStart();
if (autoFocus && ref && !hasFocusedOnMount.current) {
ref.focusAtStart();
hasFocusedOnMount.current = true;
}
},
[autoFocus]