Skip to content

Commit

Permalink
Respect meta-keys when navigating in Tabs, ToggleGroup (#3041)
Browse files Browse the repository at this point in the history
* bug: RovingFocus now respects alt-keys

* memo: changeset
  • Loading branch information
KenAJoh authored Jul 8, 2024
1 parent 420c5c3 commit 2fe2586
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-pots-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": patch
---

Tabs, ToggleGroup: Rovingfocus now respects shift, alt, ctrl and meta-keys when navigating.
9 changes: 8 additions & 1 deletion @navikt/core/react/src/tabs/parts/tablist/useTabList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ export function useTabList() {
End: lastTab,
};

const shouldDoAction = !(
event.shiftKey ||
event.ctrlKey ||
event.altKey ||
event.metaKey
);

const action = keyMap[event.key];

if (action) {
if (shouldDoAction && action) {
event.preventDefault();
action(event);
} else if (event.key === "Tab") {
Expand Down
9 changes: 8 additions & 1 deletion @navikt/core/react/src/toggle-group/parts/useToggleItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ export function useToggleItem<P extends UseToggleItemProps>(
End: lastTab,
};

const shouldDoAction = !(
event.shiftKey ||
event.ctrlKey ||
event.altKey ||
event.metaKey
);

const action = keyMap[event.key];

if (action) {
if (shouldDoAction && action) {
event.preventDefault();
action(event);
} else if (event.key === "Tab") {
Expand Down

0 comments on commit 2fe2586

Please sign in to comment.