Skip to content

Commit

Permalink
Merge pull request #1833 from ag-grid/olegat/keynav_no_modifier_keypr…
Browse files Browse the repository at this point in the history
…esses

AG-11956 Ignore key-presses with modifiers in keynavUtil.ts
  • Loading branch information
olegat committed Jun 24, 2024
2 parents d1979df + 9c79ed7 commit ef84ed6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/ag-charts-community/src/util/keynavUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ function addEscapeEventListener(
});
}

function matchesKey(event: KeyboardEvent, key: string, ...morekeys: string[]): boolean {
return (
!(event.altKey || event.ctrlKey || event.metaKey) &&
(event.key === key || morekeys.some((altkey) => event.key === altkey))
);
}

function linkTwoButtons(destroyFns: (() => void)[], src: HTMLElement, dst: HTMLElement | undefined, key: string) {
if (!dst) return;

addRemovableEventListener(destroyFns, src, 'keydown', (event: KeyboardEvent) => {
if (event.key !== key) return;
dst.focus();
if (matchesKey(event, key)) {
dst.focus();
}
});
}

Expand All @@ -40,7 +48,7 @@ function linkThreeButtons(
linkTwoButtons(destroyFns, curr, prev, prevKey);
linkTwoButtons(destroyFns, curr, next, nextKey);
addRemovableEventListener(destroyFns, curr, 'keydown', (event: KeyboardEvent) => {
if (event.key === nextKey || event.key === prevKey) {
if (matchesKey(event, nextKey, prevKey)) {
event.preventDefault();
}
});
Expand Down

0 comments on commit ef84ed6

Please sign in to comment.