React Aria and React Spectrum have a new home!
useRadioGroupState
Provides state management for a radio group component. Provides a name for the group, and manages selection and focus state.
| install | yarn add react-stately |
|---|---|
| version | 3.42.0 |
| usage | import {useRadioGroupState} from 'react-stately' |
API#
useRadioGroupState(
(props: RadioGroupProps
)): RadioGroupState
Interface#
Properties
| Name | Type | Description |
isDisabled | boolean | Whether the radio group is disabled. |
isReadOnly | boolean | Whether the radio group is read only. |
isRequired | boolean | Whether the radio group is required. |
isInvalid | boolean | Whether the radio group is invalid. |
selectedValue | string | null | The currently selected value. |
defaultSelectedValue | string | null | The default selected value. |
lastFocusedValue | string | null | The value of the last focused radio. |
realtimeValidation | ValidationResult | Realtime validation results, updated as the user edits the value. |
displayValidation | ValidationResult | Currently displayed validation results, updated when the user commits their changes. |
Methods
| Method | Description |
setSelectedValue(
(value: string
| | null
)): void | Sets the selected value. |
setLastFocusedValue(
(value: string
| | null
)): void | Sets the last focused value. |
updateValidation(
(result: ValidationResult
)): void | Updates the current validation result. Not displayed to the user until commitValidation is called. |
resetValidation(): void | Resets the displayed validation state to valid when the user resets the form. |
commitValidation(): void | Commits the realtime validation so it is displayed to the user. |
Example#
See the docs for useRadioGroup in react-aria for an example of useRadioGroupState.