react-spectrum
react-spectrum copied to clipboard
useSwitch ignores onChange prop
🐛 Bug Report
When using the useSwitch hook to build a switch, the AriaSwitchProps defines an onChange-handler that should be called when the switch gets toggled. However this handler is ignored when passed as a prop.
🤔 Expected Behavior
The onChange handler that is passed as a prop should be called with the new selected state as argument.
😯 Current Behavior
The passed onChange handler is ignored.
💁 Possible Solution
Call the user defined onChange handler in the onChange handler that is used to set the new state.
It should be getting called. Here's a working codesandbox: https://codesandbox.io/s/react-aria-switch-example-42ydb6?file=/src/App.tsx
Are you able to reproduce the issue you're seeing in a codesandbox, or post a code snippet?
Ah, my bad. I didn't pass the props to useToggleState(). Thanks for the quick response and the codesandbox!