Skip to content

Commit f7a188c

Browse files
Copilotimnasnainaec
andcommitted
Remove setTimeout delay and blur button on open to prevent focus restoration
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
1 parent 3b9c290 commit f7a188c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/components/Buttons/NoteButton.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ interface NoteButtonProps {
1919
export default function NoteButton(props: NoteButtonProps): ReactElement {
2020
const [noteOpen, setNoteOpen] = useState<boolean>(false);
2121

22+
const handleOpen = (): void => {
23+
setNoteOpen(true);
24+
// Blur the button to prevent it from receiving focus when dialog closes
25+
if (document.activeElement instanceof HTMLElement) {
26+
document.activeElement.blur();
27+
}
28+
};
29+
2230
return (
2331
<>
2432
<IconButtonWithTooltip
@@ -36,7 +44,7 @@ export default function NoteButton(props: NoteButtonProps): ReactElement {
3644
/>
3745
)
3846
}
39-
onClick={props.updateNote ? () => setNoteOpen(true) : undefined}
47+
onClick={props.updateNote ? handleOpen : undefined}
4048
side="top"
4149
size="small"
4250
text={props.noteText || undefined}

src/components/DataEntry/DataEntryTable/NewEntry/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ export enum FocusTarget {
3636
Vernacular,
3737
}
3838

39-
/** Delay in ms to ensure focus change happens after browser focus management completes */
40-
const FOCUS_DELAY_MS = 10;
41-
4239
interface NewEntryProps {
4340
analysisLang: WritingSystem;
4441
vernacularLang: WritingSystem;
@@ -280,9 +277,7 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
280277
<NoteButton
281278
buttonId={NewEntryId.ButtonNote}
282279
noteText={submitting ? "" : newNote}
283-
onExited={() =>
284-
setTimeout(() => focus(FocusTarget.Gloss), FOCUS_DELAY_MS)
285-
}
280+
onExited={() => focus(FocusTarget.Gloss)}
286281
updateNote={setNewNote}
287282
/>
288283
)}

0 commit comments

Comments
 (0)