Skip to content

[checkbox][switch][slider] Checkbox, Switch, and Slider validate twice from a single user interaction #4902

Closed

Description

@nami8824

Bug report

Current behavior

When Checkbox.Root, Switch.Root, or Slider.Root is inside a Field.Root with validationMode="onChange", a single user interaction calls validate twice.

Expected behavior

A single user interaction should call validate once.

Reproducible example

The issue can be reproduced by adding these tests.

packages/react/src/checkbox/root/CheckboxRoot.test.tsx:

it('validates once when changed by the user', async () => {
  const validate = vi.fn();

  await render(
    <Field.Root validationMode="onChange" validate={validate}>
      <Checkbox.Root />
    </Field.Root>,
  );

  fireEvent.click(screen.getByRole('checkbox'));

  expect(validate).toHaveBeenCalledOnce();
});

packages/react/src/switch/root/SwitchRoot.test.tsx:

it('validates once when changed by the user', async () => {
  const validate = vi.fn();

  await render(
    <Field.Root validationMode="onChange" validate={validate}>
      <Switch.Root />
    </Field.Root>,
  );

  fireEvent.click(screen.getByRole('switch'));

  expect(validate).toHaveBeenCalledOnce();
});

packages/react/src/slider/root/SliderRoot.test.tsx:

it('validates once when changed by the user', async () => {
  const validate = vi.fn();

  await render(
    <Field.Root validationMode="onChange" validate={validate}>
      <Slider.Root defaultValue={0}>
        <Slider.Control>
          <Slider.Thumb />
        </Slider.Control>
      </Slider.Root>
    </Field.Root>,
  );

  fireEvent.change(screen.getByRole('slider'), { target: { value: '1' } });

  expect(validate).toHaveBeenCalledOnce();
});

Each test currently fails with:

expected "vi.fn()" to be called once, but got 2 times

Commands to reproduce:

pnpm test:jsdom CheckboxRoot --no-watch -t "validates once when changed by the user"
pnpm test:jsdom SwitchRoot --no-watch -t "validates once when changed by the user"
pnpm test:jsdom SliderRoot --no-watch -t "validates once when changed by the user"

Base UI version

v1.5.0

Which browser are you using?

Not browser-specific; reproduced in the jsdom test environment.

Which OS are you using?

macOS

Which assistive tech are you using (if applicable)?

Not applicable.

Additional context

This may be caused by two validation paths running for the same user interaction.

  1. Its native input receives the change event and validates through getInputValidationProps().onChange.
  2. The component state is then updated, and useValueChanged(...) validates the updated value again.

Activity

  1. added
    status: waiting for maintainer
    on May 24, 2026
  2. added
    component: switch
    component: slider
    type: bug
    component: checkbox
    and removed
    status: waiting for maintainer
    on May 26, 2026
  3. github-actions commented on May 27, 2026

    @github-actions

    This fix will be available in the next npm release of Base UI.

    In the meantime, you can try it out on our Canary release channel:

    npm i https://pkg.pr.new/@base-ui/react@4911
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: checkboxcomponent: slidercomponent: switchtype: bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions