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

Issue Fix: use-focus-trap doesn't handle Radio Groups well #4856

Merged
merged 11 commits into from
Oct 3, 2023
Merged
8 changes: 4 additions & 4 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@
version "0.0.0"
uid ""

"@mantine/[email protected].0-beta.5":
version "7.0.0-beta.5"
resolved "https://registry.yarnpkg.com/@mantine/store/-/store-7.0.0-beta.5.tgz#24d55bf2dc45e33e9005e131b2944bbf3d19c263"
integrity sha512-smKxfat+Gne95qaMivjUJbifIxp4/ptxVnSkyw6RD580aspexRQOIGRtX/OeMmS6Yz9D5beLkl6Q1C/8/RHNhg==
"@mantine/[email protected].2":
version "7.0.2"
resolved "https://registry.yarnpkg.com/@mantine/store/-/store-7.0.2.tgz#cb3288829c75c5d6b96555cab33c58c72cc32c3d"
integrity sha512-0OAca3r/IQ6c7Pb6YvmL+5hyCo31vA3SfZKTwb1KquX4SjFfjpdhPuTR/tzjmxqwIw4zkzXH/7ckNZ/AHHwm8A==

"@mantine/store@link:../src/mantine-store":
version "0.0.0"
Expand Down
15 changes: 14 additions & 1 deletion src/mantine-hooks/src/use-focus-trap/scope-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ export function scopeTab(node: HTMLElement, event: KeyboardEvent) {
}
const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];
const root = node.getRootNode() as unknown as DocumentOrShadowRoot;
const leavingFinalTabbable = finalTabbable === root.activeElement || node === root.activeElement;
let leavingFinalTabbable = finalTabbable === root.activeElement || node === root.activeElement;

// Handle the case of the active element being in a RadioGroup with the finalTabbable element
const activeElement = root.activeElement as Element;
const activeElementIsRadio =
activeElement.tagName === 'INPUT' && activeElement.getAttribute('type') === 'radio';
if (activeElementIsRadio) {
const activeRadioGroup = tabbable.filter(
(element) =>
element.getAttribute('type') === 'radio' &&
element.getAttribute('name') === activeElement.getAttribute('name')
);
leavingFinalTabbable = activeRadioGroup.includes(finalTabbable);
}

if (!leavingFinalTabbable) {
return;
Expand Down
28 changes: 4 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6048,30 +6048,10 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001449:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not downgrade caniuse-lite.

Copy link
Contributor Author

@Shresth72 Shresth72 Sep 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a previous commit, it was resolved earlier. It's now same as the master repo

version "1.0.30001457"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001457.tgz#6af34bb5d720074e2099432aa522c21555a18301"
integrity sha512-SDIV6bgE1aVbK6XyxdURbUE89zY7+k1BBBaOwYwkNCglXlel/E7mELiHC64HQ+W0xSKlqWhV9Wh7iHxUjMs4fA==

caniuse-lite@^1.0.30001109:
version "1.0.30001458"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001458.tgz#871e35866b4654a7d25eccca86864f411825540c"
integrity sha512-lQ1VlUUq5q9ro9X+5gOEyH7i3vm+AYVT1WDCVB69XOZ17KZRhnZ9J0Sqz7wTHQaLBJccNCHq8/Ww5LlOIZbB0w==

caniuse-lite@^1.0.30001219:
version "1.0.30001232"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001232.tgz#2ebc8b6a77656fd772ab44a82a332a26a17e9527"
integrity sha512-e4Gyp7P8vqC2qV2iHA+cJNf/yqUKOShXQOJHQt81OHxlIZl/j/j3soEA0adAQi8CPUQgvOdDENyQ5kd6a6mNSg==

caniuse-lite@^1.0.30001332:
version "1.0.30001341"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001341.tgz#59590c8ffa8b5939cf4161f00827b8873ad72498"
integrity sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA==

caniuse-lite@^1.0.30001503:
version "1.0.30001517"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001517.tgz#90fabae294215c3495807eb24fc809e11dc2f0a8"
integrity sha512-Vdhm5S11DaFVLlyiKu4hiUTkpZu+y1KA/rZZqVQfOD5YdDT/eQKlkt7NaE0WGOFgX32diqt9MiP9CAiFeRklaA==
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001332, caniuse-lite@^1.0.30001449, caniuse-lite@^1.0.30001503:
version "1.0.30001540"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001540.tgz"
integrity sha512-9JL38jscuTJBTcuETxm8QLsFr/F6v0CYYTEU6r5+qSM98P2Q0Hmu0eG1dTG5GBUmywU3UlcVOUSIJYY47rdFSw==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down