Skip to content

Commit

Permalink
[dashboard] added focus handling to onEnter listener
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKoehnlein authored and roboquat committed Jan 4, 2022
1 parent 7a07ae5 commit ee68fdd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/dashboard/src/components/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ export default function ConfirmationModal(props: {
child.push(props.children);
}
}
const cancelButtonRef = useRef<HTMLButtonElement>(null);

const buttons = [
<button className="secondary" onClick={props.onClose} autoFocus>Cancel</button>,
<button className="secondary" onClick={props.onClose} autoFocus ref={cancelButtonRef}>Cancel</button>,
<button className="ml-2 danger" onClick={props.onConfirm} disabled={props.buttonDisabled}>
{props.buttonText || "Yes, I'm Sure"}
</button>,
Expand All @@ -63,6 +64,10 @@ export default function ConfirmationModal(props: {
visible={props.visible === undefined ? true : props.visible}
onClose={props.onClose}
onEnter={() => {
if (cancelButtonRef?.current?.contains(document.activeElement)) {
props.onClose();
return false;
}
if (buttonDisabled.current) {
return false
}
Expand Down

0 comments on commit ee68fdd

Please sign in to comment.