diff --git a/src/components/radio-group/RadioGroup.stories.tsx b/src/components/radio-group/RadioGroup.stories.tsx index 86bc478..6516e75 100644 --- a/src/components/radio-group/RadioGroup.stories.tsx +++ b/src/components/radio-group/RadioGroup.stories.tsx @@ -82,7 +82,24 @@ export const RequiredNumber = radioGroupStory({ options: ratingOptions, getValue: (value) => value, getLabel: (value) => Array(value + 1).join("⭐"), - // label="How do you like the RadioGroup component?" + }, +}); + +export const InitializedNumber = radioGroupStory({ + parameters: { + docs: { + description: { + story: + "The `initialValue` initializes the field, accepting values returned from the `getValue` prop.", + }, + }, + }, + args: { + field: numberField(), + initialValue: 4, + options: ratingOptions, + getValue: (value) => value, + getLabel: (value) => Array(value + 1).join("⭐"), }, }); diff --git a/src/components/radio-group/RadioGroup.test.tsx b/src/components/radio-group/RadioGroup.test.tsx index f12a173..4441c89 100644 --- a/src/components/radio-group/RadioGroup.test.tsx +++ b/src/components/radio-group/RadioGroup.test.tsx @@ -82,4 +82,27 @@ describe("", () => { expect(onSubmit).toHaveBeenCalledWith({ field: "some" }); }); }); + + describe("initialValue prop", () => { + it("sets the field value", async () => { + const props = { + field: stringField(), + options: ["none", "some", "all"], + getLabel: (val: string) => val, + getValue: (val: string) => val, + }; + const form = formAtom({ field: props.field }); + const { result } = renderHook(() => useFormSubmit(form)); + render(); + + expect(screen.getByLabelText("some")).toBeChecked(); + + const onSubmit = vi.fn(); + await act(async () => { + result.current(onSubmit)(); + }); + + expect(onSubmit).toHaveBeenCalledWith({ field: "some" }); + }); + }); }); diff --git a/src/components/radio-group/RadioGroup.tsx b/src/components/radio-group/RadioGroup.tsx index 55152ad..77162d6 100644 --- a/src/components/radio-group/RadioGroup.tsx +++ b/src/components/radio-group/RadioGroup.tsx @@ -1,32 +1,35 @@ import { SelectField, + SelectFieldProps, UseOptionsProps, - UseSelectFieldProps, useOptions, useSelectFieldProps, } from "../../hooks"; -export type RadioGroupProps = Omit< - UseOptionsProps