radix-ui / themes

Radix Themes is an open-source component library optimized for fast development, easy maintenance, and accessibility. Maintained by @workos.
https://radix-ui.com/themes
MIT License
5.24k stars 187 forks source link

Form validation + Select integration seems don't work #558

Open tuchk4 opened 1 month ago

tuchk4 commented 1 month ago

(simplified examples)

Select:

import { Select as BaseSelect } from "@radix-ui/themes";

export const Select = React.forwardRef(({ value, onChange }, ref) => {
  return (
    <BaseSelect.Root
      name={"complexity"}
      size={size}
      required
      value={value}
      onValueChange={onChange}
    >
      {/* Important to pass ref to Trigger */}
      <BaseSelect.Trigger ref={ref} placeholder={'Select value'} />
      <BaseSelect.Content>
        <BaseSelect.Item value={"1"}>1</BaseSelect.Item>
        <BaseSelect.Item value={"2"}>2</BaseSelect.Item>
      </BaseSelect.Content>
    </BaseSelect.Root>
  );
});

Form:

<Form.Root>
  <Form.Field name={"foo"}>
    <Form.ValidityState>
      {(validity) => {
        console.log(validity);
        return null;
      }}
    </Form.ValidityState>
    <Form.Control asChild>
      <Select />
    </Form.Control>
  </Form.Field>
</Form.Root>

Expected result:

Actual result:

radix select:

image

also getting this warning on submit if select's value is undefined:

Blocked aria-hidden on a <select> element because the element that just received focus must not be hidden from assistive technology users. Avoid using aria-hidden on a focused element or its ancestor. Consider using the inert attribute instead, which will also prevent focus. For more details, see the aria-hidden section of the WAI-ARIA specification at https://w3c.github.io/aria/#aria-hidden. 
tuchk4 commented 1 month ago

🤔