Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue: user may navigate forward with an opened modal #8748

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- User may navigate forward with a keyboard when a modal opened
(<https://github.com/cvat-ai/cvat/pull/8748>)
13 changes: 9 additions & 4 deletions cvat-ui/src/utils/mousetrap-react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,29 @@ export default function GlobalHotKeys(props: Props): JSX.Element {

Mousetrap.prototype.stopCallback = function (e: KeyboardEvent, element: Element, combo: string): boolean {
if (element.tagName === 'INPUT' || element.tagName === 'SELECT' || element.tagName === 'TEXTAREA') {
// stop for input, select, and textarea
// do not trigger any shortcuts if input field is one of [input, select, textarea]
return true;
}

const activeSequences = Object.values(applicationKeyMap).map((keyMap) => [...keyMap.sequences]).flat();
if (activeSequences.some((sequence) => sequence.startsWith(combo))) {
// prevent default behaviour of the event if potentially one of active shortcuts will be trigerred
e?.preventDefault();
}

// stop when modals are opened
const someModalsOpened = Array.from(
const anyModalsOpened = Array.from(
window.document.getElementsByClassName('ant-modal'),
).some((el) => (el as HTMLElement).style.display !== 'none');

if (someModalsOpened) {
if (anyModalsOpened) {
const modalClosingSequences = ['SWITCH_SHORTCUTS', 'SWITCH_SETTINGS']
.map((key) => [...(applicationKeyMap[key]?.sequences ?? [])]).flat();
return !modalClosingSequences.includes(combo) && !modalClosingSequences.some((seq) => seq.startsWith(combo));

return !modalClosingSequences.some((seq) => {
const seqFragments = seq.split('+');
return combo.split('+').every((key, i) => seqFragments[i] === key);
});
}

return false;
Expand Down
Loading