The Toggler component no longer worked when the onToggle function was passed directly to an onClick function. There are two ways to call onToggle:
// Give an argument to toggle to
onToggle(true) // flip toggle to true
onToggle(true) // flip toggle to true
// Flip whatever the current toggle is
onToggle() // false -> true and true -> false
Before 10.x, the argument passed to onToggle was checked against the boolean type. After 10.x, it was just checked if it wasn't undefined. Normally this would be fine, but a common use case (including what was in the docs!) was to pass it directly on an onClick function:
<button onClick={onToggle} />
Since the onClick functions pass an event as their argument, the first way to call onToggle was triggered instead of the second way.
Test plan
I verified that this works by looking at the docs:
This fixes the toggle behavior demonstrated in https://github.com/smooth-code/smooth-ui/issues/138.
Summary
The
Toggler
component no longer worked when theonToggle
function was passed directly to an onClick function. There are two ways to call onToggle:Before 10.x, the argument passed to
onToggle
was checked against the boolean type. After 10.x, it was just checked if it wasn't undefined. Normally this would be fine, but a common use case (including what was in the docs!) was to pass it directly on an onClick function:Since the onClick functions pass an event as their argument, the first way to call
onToggle
was triggered instead of the second way.Test plan
I verified that this works by looking at the docs:
Before:
After: