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

Respect meta-keys when navigating in Tabs, ToggleGroup #3041

Merged
merged 2 commits into from
Jul 8, 2024
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
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 = !(
KenAJoh marked this conversation as resolved.
Show resolved Hide resolved
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
Loading