Repository navigation
Closed
Labels
component: checkboxChanges related to the checkbox component.component: sliderChanges related to the slider component.component: switchChanges related to the switch component.type: bugIt doesn't behave as expected.
Description
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.
- Its native input receives the change event and validates through
getInputValidationProps().onChange. - The component state is then updated, and
useValueChanged(...)validates the updated value again.
Metadata
Metadata
Assignees
Labels
component: checkboxChanges related to the checkbox component.component: sliderChanges related to the slider component.component: switchChanges related to the switch component.type: bugIt doesn't behave as expected.
Activity
github-actions commentedon May 27, 2026
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: