smooth-code / smooth-ui

Modern React UI library 💅👩‍🎤🍭
MIT License
1.59k stars 101 forks source link

fix: fix toggle behavior #139

Closed petevk closed 5 years ago

petevk commented 5 years ago

This fixes the toggle behavior demonstrated in https://github.com/smooth-code/smooth-ui/issues/138.

Summary

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:

Before: smoothui before

After: smoothui after

gregberge commented 5 years ago

Thanks!