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

fix tabbable for radios #2357

Merged
merged 4 commits into from
Feb 3, 2025
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
1 change: 1 addition & 0 deletions docs/pages/resources/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ New versions of Shoelace are released as-needed and generally occur when a criti

- Improved performance of `<sl-select>` when using a large number of options [#2318]
- Updated the Japanese translation [#2329]
- Fixed a bug with radios in `<sl-dialog>` focus trapping.

## 2.19.1

Expand Down
16 changes: 13 additions & 3 deletions src/internal/tabbable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,19 @@ function isTabbable(el: HTMLElement) {
return false;
}

// Radios without a checked attribute are not tabbable
if (tag === 'input' && el.getAttribute('type') === 'radio' && !el.hasAttribute('checked')) {
return false;
if (tag === 'input' && el.getAttribute('type') === 'radio') {
const rootNode = el.getRootNode() as HTMLElement;

const findRadios = `input[type='radio'][name="${el.getAttribute('name')}"]`;
const firstChecked = rootNode.querySelector(`${findRadios}:checked`);

if (firstChecked) {
return firstChecked === el;
}

const firstRadio = rootNode.querySelector(findRadios);

return firstRadio === el;
}

if (!isVisible(el)) {
Expand Down
Loading