Skip to content

Commit

Permalink
fix: escape in toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Wizard committed Apr 13, 2023
1 parent 33eaa57 commit 35f7b4a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apis/nucleus/src/components/ActionsToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ function ActionsToolbar({
};

const handleActionsKeyDown = useMemo(
() => getActionsKeyDownHandler({ keyboardNavigation, focusHandler, getEnabledButton }),
[keyboardNavigation, focusHandler, getEnabledButton]
() => getActionsKeyDownHandler({ keyboardNavigation, focusHandler, getEnabledButton, selections }),
[keyboardNavigation, focusHandler, getEnabledButton, selections]
);

useEffect(
Expand Down
10 changes: 9 additions & 1 deletion apis/nucleus/src/components/actions-toolbar-keydown.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const focusButton = (index) => {
btn.focus();
};

export default function getActionsKeyDownHandler({ keyboardNavigation, focusHandler, getEnabledButton }) {
export default function getActionsKeyDownHandler({ keyboardNavigation, focusHandler, getEnabledButton, selections }) {
const handleActionsKeyDown = (evt) => {
const { target, nativeEvent } = evt;
const { keyCode } = nativeEvent;
Expand Down Expand Up @@ -52,6 +52,14 @@ export default function getActionsKeyDownHandler({ keyboardNavigation, focusHand
}
}
break;
case KEYS.ESCAPE:
if (selections) {
selections.onCancel();
selections.api.cancel();
evt.preventDefault();
evt.stopPropagation();
}
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions apis/nucleus/src/components/listbox/ListBoxInline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ function ListBoxInline({ options, layout }) {
isLocked,
listboxSelectionToolbarItems,
selections,
keyboard,
});

const shouldAutoFocus = searchVisible && search === 'toggle';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default function getListboxActionProps({
isLocked,
listboxSelectionToolbarItems,
selections,
keyboard,
}) {
return {
show: showToolbar && !isDetached,
Expand All @@ -26,8 +27,12 @@ export default function getListboxActionProps({
selections: {
show: showToolbar,
api: selections,
onConfirm: () => {},
onCancel: () => {},
onConfirm: () => {
keyboard?.focus();
},
onCancel: () => {
keyboard?.focus();
},
},
};
}

0 comments on commit 35f7b4a

Please sign in to comment.