-
Notifications
You must be signed in to change notification settings - Fork 26
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
Move Toggle
, Radio
, and Checkbox
to inputs
#428
Conversation
Toggle
, Radio
, and Checkbox
to inputs
@@ -22,6 +22,17 @@ export class Toggle extends React.PureComponent { | |||
size: 'big', | |||
}; | |||
|
|||
emitChange = () => { | |||
const event = { | |||
target: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the breaking change
@@ -72,7 +72,7 @@ describe('TimeInput', () => { | |||
expect(container.querySelector('input')).toHaveAttribute('value', 'foo'); | |||
}); | |||
|
|||
it('should call onChange when chaning the value', () => { | |||
it('should call onChange when changing the value', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Super nice to get them to have the same API! Hare we sure that the Toggle is an input. I think so but at the same time wonder...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this!
value: !this.props.isChecked, | ||
}, | ||
}; | ||
this.props.onChange(event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we constructing the event ourselves? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't get it to work with the native event. You are welcome to try it, but I spent about an hour on it and got nowhere with RTL. The shape is the same now as the native event though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh really? Sorry about that...
Hmm that's weird, I would have expected this to work. I can have a look over the weekend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switching to defaultChecked
fixed the probelm
src/index.js
Outdated
|
||
export { default as Toggle } from './components/inputs/toggle'; | ||
export { default as Checkbox } from './components/inputs/checkbox'; | ||
export { default as Radio } from './components/inputs/radio'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name them consistently with the other component, so with Input
suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very valid!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed Toggle
-> ToggleInput
. If we are happy with this, I will rename the rest of them on Monday
It's being used with formik with this workaround in the MC
|
I know, I wrote that 😄 That's why I'm asking: why not simply |
The |
I can't get it to work with the native event with RTL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename them to be radio-input
, checkbox-input
and toggle-input
?
| `isDisabled` | `bool` | - | - | `false` | Disables the ToggleInput | | ||
| `isChecked` | `bool` | - | - | `false` | Checks the ToggleInput | | ||
| `onChange` | `func` | ✅ | - | - | called with the new value. | | ||
| `size` | `string` | ✅ | oneOf(['small', 'big']) | `big` | The size of the ToggleInput component. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some props are missing here
@@ -38,7 +38,7 @@ export class Toggle extends React.PureComponent { | |||
className={styles.inputWrapper} | |||
id={this.props.id} | |||
name={this.props.name} | |||
onChange={() => this.props.onChange(!this.props.isChecked)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
I updated the PR with the renaming of the rest of the switches |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉🙌
Summary
Moves
Checkbox
,Radio
, andSwitch
out of thesrc/components/switches
folder into thesrc/components/inputs
folder. Also moves them to theinputs
section of Storybook.BREAKING CHANGE
Toggle
's now returns an event from it's onChange with the shapeToggle
is nowToggleInput
Radio
is nowRadioInput
Checkbox
is nowCheckboxInput
This is to unify the API with all the other inputs (including Checkbox and Radio), which already emit events.
Closes #318