Enter key for toggle component is not working as expected #9570
Labels
component: toggle
package: react
carbon-components-react
severity: 3
https://ibm.biz/carbon-severity
status: waiting for author's response 💬
type: bug 🐛
What package(s) are you using?
carbon-components
carbon-components-react
Detailed description
I was creating a toggle that sets the toggled value from formik context on load. I also have a onChange that checks a custom
viewOnly
prop before making any change to the context variable. I want to mimic this toggle as read-only but visible to screen reader. The space bar and the mouse click works as expected that does not let it toggle when inviewOnly
mode but for some reason the enter key lets it toggle on and off even though I dont change anything on the onChange. I triedevent.preventDefault()
and that didnt help.Steps to reproduce the issue
toggled
prop to a state variableonChange
prop should only set the toggle on some conditionAdditional information
My code:
I found this line that could be changing the toggle no matter what and then call then onChange and onToggle:
https://github.com/carbon-design-system/carbon-components-react/blob/938a0fe63dd705285a3fdebe42ac378ac9dd3d78/src/components/Toggle/Toggle.js#L119
The text was updated successfully, but these errors were encountered: