Skip to content

Accept tabIndex on <RadioGroup> component #3646

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

Merged
merged 2 commits into from
Feb 21, 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
11 changes: 6 additions & 5 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Accept `tabIndex` on the `Checkbox` component ([#3645](https://github.com/tailwindlabs/headlessui/pull/3645))
- Accept `tabIndex` on the `RadioGroup` component ([#3646](https://github.com/tailwindlabs/headlessui/pull/3646))

### Fixed

- Use correct `ownerDocument` when using internal `<Portal/>` element ([#3594](https://github.com/tailwindlabs/headlessui/pull/3594))
- Use correct `ownerDocument` when using internal `Portal` component ([#3594](https://github.com/tailwindlabs/headlessui/pull/3594))
- Bump `@tanstack/react-virtual` to be fix warnings in React 19 projects ([#3588](https://github.com/tailwindlabs/headlessui/pull/3588))
- Fix `aria-invalid` attributes to have a valid `'true'` value ([#3639](https://github.com/tailwindlabs/headlessui/pull/3639))

### Added

- Accept `tabIndex` on `Checkbox` component ([#3645](https://github.com/tailwindlabs/headlessui/pull/3645))

## [2.2.0] - 2024-10-25

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ let RadioGroupDataContext = createContext<
containsCheckedOption: boolean
disabled: boolean
compare(a: unknown, z: unknown): boolean
tabIndex: number
} & StateDefinition)
| null
>(null)
Expand Down Expand Up @@ -178,6 +179,7 @@ function RadioGroupFn<TTag extends ElementType = typeof DEFAULT_RADIO_GROUP_TAG,
by,
disabled = providedDisabled || false,
defaultValue: _defaultValue,
tabIndex = 0,
...theirProps
} = props
let compare = useByComparator(by)
Expand Down Expand Up @@ -285,8 +287,8 @@ function RadioGroupFn<TTag extends ElementType = typeof DEFAULT_RADIO_GROUP_TAG,
})

let radioGroupData = useMemo<_Data>(
() => ({ value, firstOption, containsCheckedOption, disabled, compare, ...state }),
[value, firstOption, containsCheckedOption, disabled, compare, state]
() => ({ value, firstOption, containsCheckedOption, disabled, compare, tabIndex, ...state }),
[value, firstOption, containsCheckedOption, disabled, compare, tabIndex, state]
)
let radioGroupActions = useMemo<_Actions>(
() => ({ registerOption, change: triggerChange }),
Expand Down Expand Up @@ -424,8 +426,8 @@ function OptionFn<
'aria-disabled': disabled ? true : undefined,
tabIndex: (() => {
if (disabled) return -1
if (checked) return 0
if (!data.containsCheckedOption && isFirstOption) return 0
if (checked) return data.tabIndex
if (!data.containsCheckedOption && isFirstOption) return data.tabIndex
return -1
})(),
onClick: disabled ? undefined : handleClick,
Expand Down Expand Up @@ -547,8 +549,8 @@ function RadioFn<
'aria-disabled': disabled ? true : undefined,
tabIndex: (() => {
if (disabled) return -1
if (checked) return 0
if (!data.containsCheckedOption && isFirstOption) return 0
if (checked) return data.tabIndex
if (!data.containsCheckedOption && isFirstOption) return data.tabIndex
return -1
})(),
autoFocus,
Expand Down