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: add number type in value #6636

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
10 changes: 5 additions & 5 deletions packages/@react-stately/radio/src/useRadioGroupState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ export interface RadioGroupState extends FormValidationState {
readonly isInvalid: boolean,

/** The currently selected value. */
readonly selectedValue: string | null,
readonly selectedValue: string | number | null,

/** Sets the selected value. */
setSelectedValue(value: string | null): void,
setSelectedValue(value: string | number | null): void,

/** The value of the last focused radio. */
readonly lastFocusedValue: string | null,
readonly lastFocusedValue: string | number | null,

/** Sets the last focused value. */
setLastFocusedValue(value: string | null): void
setLastFocusedValue(value: string | number | null): void
}

let instance = Math.round(Math.random() * 10000000000);
Expand All @@ -66,7 +66,7 @@ export function useRadioGroupState(props: RadioGroupProps): RadioGroupState {
// Preserved here for backward compatibility. React Aria now generates the name instead of stately.
let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);
let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue ?? null, props.onChange);
let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);
let [lastFocusedValue, setLastFocusedValue] = useState<string | number | null>(null);

let validation = useFormValidationState({
...props,
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-types/radio/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface RadioProps extends FocusableProps {
* The value of the radio button, used when submitting an HTML form.
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#Value).
*/
value: string,
value: string | number,
/**
* The label for the Radio. Accepts any renderable node.
*/
Expand Down