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

[Field] Does not invalidate certain required controls #1425

Open
mj12albert opened this issue Feb 6, 2025 · 1 comment
Open

[Field] Does not invalidate certain required controls #1425

mj12albert opened this issue Feb 6, 2025 · 1 comment
Labels
bug 🐛 Something doesn't work component: field component: radio group This is the name of the generic UI component, not the React module! component: select This is the name of the generic UI component, not the React module! has workaround

Comments

@mj12albert
Copy link
Member

Bug report

Reproducible example

RadioGroup: https://codesandbox.io/p/sandbox/sweet-brattain-q9ptqr
Select: https://codesandbox.io/p/sandbox/eloquent-pond-cgnlg5

Current behavior

<Field.Root validationMode="onBlur">
  <Select.Root required>
    {/* the rest of the select */}
  </Select.Root>
  <Field.Error match="valueMissing">This field is required</Field.Error>
</Field.Root>

When there is no initial value (e.g. no defaultValue/value or defaultValue="") and the validation mode is "onBlur", Tabbing through the controls without making any selection doesn't not trigger the error

Expected behavior

Validate different types of empty values correctly

Base UI version

master & 1.0.0-alpha.5

Additional context

Only tried Input, RadioGroup and Select so far

@mj12albert mj12albert added bug 🐛 Something doesn't work component: field status: waiting for maintainer These issues haven't been looked at yet by a maintainer component: select This is the name of the generic UI component, not the React module! component: radio group This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 6, 2025
@mj12albert
Copy link
Member Author

A workaround is to use a validation function and match="customError":

<Field.Root
  validationMode="onBlur"
  validate={(value) => {
    if (value == null) {
      return "This field is required";
    }
    return null;
  }}
>
  <Select.Root required>
    {/* the rest of the select */}
  </Select.Root>
  <Field.Error match="customError" />
</Field.Root>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: field component: radio group This is the name of the generic UI component, not the React module! component: select This is the name of the generic UI component, not the React module! has workaround
Projects
None yet
Development

No branches or pull requests

1 participant