Skip to content

Commit ee68fdd

Browse files
JanKoehnleinroboquat
authored andcommitted
[dashboard] added focus handling to onEnter listener
1 parent 7a07ae5 commit ee68fdd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

components/dashboard/src/components/ConfirmationModal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ export default function ConfirmationModal(props: {
4343
child.push(props.children);
4444
}
4545
}
46+
const cancelButtonRef = useRef<HTMLButtonElement>(null);
4647

4748
const buttons = [
48-
<button className="secondary" onClick={props.onClose} autoFocus>Cancel</button>,
49+
<button className="secondary" onClick={props.onClose} autoFocus ref={cancelButtonRef}>Cancel</button>,
4950
<button className="ml-2 danger" onClick={props.onConfirm} disabled={props.buttonDisabled}>
5051
{props.buttonText || "Yes, I'm Sure"}
5152
</button>,
@@ -63,6 +64,10 @@ export default function ConfirmationModal(props: {
6364
visible={props.visible === undefined ? true : props.visible}
6465
onClose={props.onClose}
6566
onEnter={() => {
67+
if (cancelButtonRef?.current?.contains(document.activeElement)) {
68+
props.onClose();
69+
return false;
70+
}
6671
if (buttonDisabled.current) {
6772
return false
6873
}

0 commit comments

Comments
 (0)