Skip to content

RadioGroup, Select, DatePicker, DateRangePicker, TimeField validation behaviour changed from v 1.4.0 to v1.5.0 #7715

Closed
@janaHehr

Description

@janaHehr

Provide a general summary of the issue here

The following components changed their validation behaviour when they are marked as required:

  • RadioGroup
  • Select
  • DatePicker
  • DateRangePicker
  • TimeField

An required <Select isRequired/> does not trigger the validation when no entry is selected. The validate function is only called when an entry is selected.

import {
  Form,
  FieldError,
  Button,
  SelectValue,
  Popover,
  ListBox,
  ListBoxItem,
  Label,
  Key,
  Select,
} from "react-aria-components";

export default function App() {
  function validate(value: Key) {
    console.log("val select", value, value);
    if (!value) return "Choose wisely!";
  }

  return (
    <div className="App">
      <Form>
        <Select name="animal" isRequired validate={validate}>
          <Label>Favorite Animal</Label>
          <Button>
            <SelectValue />
            <span aria-hidden="true">▼</span>
          </Button>
          <div style={{ color: "red" }}>
            <FieldError />
          </div>
          <Popover>
            <ListBox>
              <ListBoxItem>Dog</ListBoxItem>
              <ListBoxItem>Cat</ListBoxItem>
            </ListBox>
          </Popover>
        </Select>
        <Button type="submit">Submit</Button>
      </Form>
    </div>
  );
}

🤔 Expected Behavior?

The <Select/> component is also validated when no entry is selected.

😯 Current Behavior

From v 1.5.0 the validation is only called when an entry is selected. When no entry is selected the browser validation now kicks in. We need full control over the error message (because they are translated into a specific user language). In v < 1.5.0 the validation was executed also when no entry was selected.

Looking in the changelog the only component-related PR was this one: PR?

💁 Possible Solution

No response

🔦 Context

No response

🖥️ Steps to Reproduce

Playground: https://codesandbox.io/p/sandbox/react-aria-component-select-forked-56kzsk?workspaceId=ws_kvjNaP9av9uABkCYVWUTZ
With v 1.4.0 the validation behaviour works when no entry is selected. Updating to v 1.5.0 or 1.6.0 changes this behaviour.

Version

1.5.0

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

iOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions