-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Programmatically toggle Switch #6375
Comments
You should use a controlled value for this use case, and update the value programmatically. The visually hidden input is dependent on the state of the Switch component, which wouldn't get updated in that case. |
Thx for the feedback. I already tried that as well, but I cannot observe that the Switch is actually moving. |
Try passing |
Reid - fantastic! (I was thinking "isSelected" was a read-only prop) Thank you very much! |
Provide a general summary of the issue here
The docs do not mention the use case how to programmatically trigger the Switch.
Since you are exposing an inputRef property, I assumed I could do it like so:
`
useEffect(() => {
ref.current.checked = true;
}, [update]
..
`
However that doesn't work.
🤔 Expected Behavior?
Switch should toggle
😯 Current Behavior
Switch doesn't toggle
💁 Possible Solution
No response
🔦 Context
No response
🖥️ Steps to Reproduce
`
useEffect(() => {
ref.current.checked = true;
}, [update]
..
`
Version
latest
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
mac
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
The text was updated successfully, but these errors were encountered: