You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://forum.primefaces.org/viewforum.php?f=57
With the above, InputSwitch doesn't toggle as onChange is triggered twice: first with a true followed by a false (if starting with a checked={true} state.
@nazar, if you wrap an input element with label, input element's change event triggers twice because of event bubbling. So when you click, first InputSwitch's value changes to true and immediately changes to false again as you mentioned. You do not have to wrap it with label,
instead of: <label> <InputSwitch checked={checked1} onChange={setChecked1} /> checked 1 </label>
you can use: <InputSwitch inputId="inputSwitch" checked={checked1} onChange={setChecked1} /> <label for="inputSwitch">checked 1</label>
Thank you for your comment @ogzogz88 - as you mentioned, I did have to resort to the non-nested usage of label in this instance.
This does limit our usage of the InputSwitch component on large forms since each input unnecessarily needs an ID attribute for the label, which is not necessary in the nested usage of label.
I'm submitting a ... (check one with "x")
Codesandbox Case (Bug Reports)
https://codesandbox.io/s/loving-panini-krzfe?file=/src/demo/InputSwitchDemo.js
Current behavior
When
InputSwitch
is enclosed in alabel
, it appears that theonChange
event triggers twice and doesn't toggle.With the above,
InputSwitch
doesn't toggle asonChange
is triggered twice: first with atrue
followed by afalse
(if starting with achecked={true}
state.The above works fine when not enclosed with a
label
Expected behavior
InputSwitch
should work as expected when enclosed with a label.Minimal reproduction of the problem with instructions
See this sandbox where Basic doesn't toggle when clicking on the
InputSwitch
and Basic only toggle when clicking on thelabel
text.The text was updated successfully, but these errors were encountered: