Closed AlvinChacko closed 1 year ago
Responded in slack, reposting here as well
I believe it’s due to us assuming that it would be passed disabled, thus eliminating any keyboard interactions. Can you explain why the disabled toggle is not suitable for your use case? I would imagine a user could be frustrated if a Toggle seems intractable, but nothing is happening when they try to click.
When the toggle is disabled the screen reader does not pick it up when tabbing thru the fields. It just skips them and doesnt even read the value. I tested accessibility using the VoiceOver on Mac
I think this will be satisfied by providing a readonly
variant of the Toggle. This would ensure that the Toggle is read by screenreaders, while remaining unable to be changed.
There is a broad workstream shaping up around read only inputs:
This is all currently being specced out by design. The individual Toggle variant progress can be tracked here:
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