-
Notifications
You must be signed in to change notification settings - Fork 5
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
Breaking: Radio and RadioGroup components #723
Conversation
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.
Looks good
docs/examples/RadioExample.jsx
Outdated
{ | ||
propType: 'className', | ||
type: 'string', | ||
note: 'This class will go into the input element', |
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.
will be applied to
Will the radio component ever be used by itself, i.e. not within a radioGroup? If not, maybe add a check for that and throw an error if someone tries to do so. |
we actually export both Radio and RadioGroup from |
3681ed9
to
ef78c7a
Compare
Codecov Report
@@ Coverage Diff @@
## master #723 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 56 59 +3
Lines 862 905 +43
Branches 181 185 +4
=====================================
+ Hits 862 905 +43
Continue to review full report at Codecov.
|
value, | ||
}; | ||
|
||
const optionalProps = _.pickBy({ |
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.
is it possible to grab these out without the pickBy
. I was reading somewhere that it is expensive.
|
||
return ( | ||
<div className="radio-component" {...expandDts(dts)}> | ||
<input {...radioInputProps} {...optionalProps} /> |
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.
not sure why we do this. I feel it is much clear to just lay it out as jsx, and only spread the optional cuz spread by default removes the undefined.
Had to pull your branch and ran it locally. |
8b4dfef
to
3af2337
Compare
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.
LGTM, apart from the appearance issue raised by @ChaoLiangSuper
just investigated |
What's even worse is that |
Echo @ChaoLiangSuper's design comment. The padding and spacing is off and needs to be resolved. Make sure the label is 5px from the input and 20px (10px each) between them. This should also be the case for the checkboxes. |
@omgaz sounds good, I'll make it happen regarding the onChange = (event) => { ... } or like this onChange = (event, checked) => { ... } |
8284f43
to
29b7b00
Compare
RadioButton.defaultProps = { | ||
disabled: false, | ||
checked: false, | ||
}; |
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'm wondering if you think it might be worthwhile to share the prop types between radios and checkboxes to ensure they have a shared API. I think it will help ensure consistency between the two components that make sense separated as components.
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.
interesting, I'll investigate that possiblity.
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.
Or as an improvement, maybe we can export only one component. And let the user passing a parameter to choose whether they want a checkbox or radio. Then we can share all other props.
🌚Note: breaking changes
v26, LOL🌝
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 still export them separately, as per icheck.
Combining checkbox and radio into 1 component is a bit over complicated imo.
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.
It makes sense to keep them separate, I think they get grouped together too often because they feel similar. I think sharing a prop type API is a good way of having consistency without coupling their logic and forcing branches in the code to differentiate logic.
padding-left: 5px; | ||
} | ||
|
||
padding-top: 10px; |
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.
Combine L12 and L13 together? padding: 10px 0
?
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 it's easier to read this way so I separate them out.
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.
Before the merge, please make sure you have already rebased the latest master and used the svg
for display. When you ready, I'm happy to do a cross-platform testing for you.
Otherwise, looking good to me.
29b7b00
to
1f0f8ed
Compare
id, | ||
className, | ||
'data-name': this.props['data-name'], | ||
}; |
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.
Is this the new standard for setting props on the input? I usually like to just see them on the input so wondering why we need the extra var and then later spread?
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 was done on Checkbox
to accommodate symphony's usage of that particular data-*
attribute. I think I need to discuss with Gary about this, and potentially remove data-*
props and let symphony changes their code.
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.
also it looks cleaner to me as well
|
||
onChangeDefault(event) { | ||
this.setState({ checked: Boolean(event.target.checked) }); | ||
if (this.props.onChange) { |
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 don't we just use defaultProps
with _.noop
to set these functions? then won't have to keep doing these conditional checks.
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.
One problem with using defaultProps
like that here is that if you change the props during the lifetime of the component and don't specify onChange
when you do so, it gets reset to to the defaultProps
value, i.e. _.noop
.
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.
Im not sure i understand how that works, if it changes with no onChange
shouldn't it reset? what else should it be
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.
Well, let's say you create a radioButton
with an initial set of props, including an onChange
function. Later on, you want to change the props, say, to set the radiobutton to disabled
without changing anything else. I think it's better to be able to do that by just passing in a disabled
prop without having to also pass in all the other props we passed in earlier.
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.
most of the time we actually just modify the props
object and pass all of them back into the component, so this is generally not a problem. You can set it as _.noop
.
Maybe it will help reducing the branches while testing as well.
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.
Im still struggling to get that implementation, is there somewhere to refer to that has an example? Sounds like some dynamic props definition which is passed to the component like:
const initialProps = {
checked: false,
disabled: false,
onChange: doAmazingStuff,
}
getRadioProps = (props = initialProps) => props;
// Somewhere out there in the wild when change happened
<Radio {...getRadioProps({ disabled: true })} />
Which doesn't sound like the right implementation to me?
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 its the right move to pass all the props back from a consumer perspective. There might be some custom implementation such as defaults described, or shouldComponentUpdate
check which depends on the props, or even the getDerivedStateFromProps
so generally i would figure its not the best practice to do anything like my example unless sure its what is desired, i.e a totally new component with totally new props not just some kind of update.
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.
Well, yeah, we could just pass in all the props every time, I really don't prefer one way over another.
|
||
render() { | ||
const { dts, className, id } = this.props; | ||
const componentProps = _.pickBy({ |
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.
Whats the pickBy
for? isnt this just the object given since I dont see a predicate.
bace57b
to
59caa27
Compare
59caa27
to
8459d00
Compare
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.
Local tested on both chrome and IE 11.
LGTM
f1c0e26
to
f10167d
Compare
f10167d
to
c8fcbc0
Compare
c8fcbc0
to
b0df36a
Compare
Merging....🌚 |
Radio
andRadioGroup
componentsRadio
andCheckbox
;RadioGroup
andCheckboxGroup
TODO:
react-icheck
(may need to go as a separate PR since it affects Checkbox and CheckboxGroup usage as well)Description
Motivation and Background Context
Resolves #700
Does this PR introduce a breaking change?
Yes
No
Radio buttons API has been changed from
react-icheck
API toadslot-ui
(see documentation)onClick
is no longer supported,onChange
should be used insteaddata-name
is no longer supported, please usedts
insteadHow Has This Been Tested?
Screenshots (if appropriate):
Check-list: