-
Notifications
You must be signed in to change notification settings - Fork 3
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
Repair Radio Checking onChange #15
base: master
Are you sure you want to change the base?
Conversation
); | ||
switch (type) { | ||
case 'radio': | ||
return <Radio {...this.props}>{children}</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.
Nice! I like this a lot. Also adds a lot more flexibility for more custom input types in the future 👍
src/components/Input/Type/Radio.js
Outdated
} = this.props; | ||
|
||
return children.map((option, idx) => ( | ||
<div key={option} className={className}> |
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.
having everything set to option
kind of limits the use of this. For example, we might want a descriptive label but a value that maps to an int.
An ideal for this would be something like what semantic-ui does (http://react.semantic-ui.com/addons/radio/#types-radio-group). Unfortunately we don't have anything like Form.Field right now though...
Okay, I see what you mean. One possibility is that we could change the
signature to accept options as both strings and shape restricted objects
['','',''] -> [{option, value},{option, value},{option, value}] to handle
your concern in the interim. Will look into it later.
…On Tue, Aug 7, 2018 at 5:18 PM Buck Perley ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/components/Input/Type/Radio.js
<#15 (comment)>:
> + render() {
+ const {
+ children,
+ className,
+ name,
+ onChange,
+ placeholder,
+ style,
+ theme,
+ type,
+ value,
+ ...otherProps
+ } = this.props;
+
+ return children.map((option, idx) => (
+ <div key={option} className={className}>
having everything set to option kind of limits the use of this. For
example, we might want a descriptive label but a value that maps to an int.
An ideal for this would be something like what semantic-ui does (
http://react.semantic-ui.com/addons/radio/#types-radio-group).
Unfortunately we don't have anything like Form.Field right now though...
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#15 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AR3NqMRlf-KO9lk-WUL2W7l58N4EhB3rks5uOi5ggaJpZM4Vy_Xw>
.
|
Yeah, I was thinking the same. Would be nice to have something more similar, but checking if it's an object and then passing it through as props should be a good fix for now 👍 |
Radio Input update complete. Edge case to consider when implementing Form wrapper is that names of inputs must be unique. Demo:
|
Improve option handling with tuple and string compatability:
|
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 there any reason why you think we should pass in an array of tuples rather than an array objects? It feels a lot clearer to me to have the object properties map to the type of options a radio button would accept. I think you should even be able to just destructure whatever is passed through and let it populate the input
element that way.
|
||
const optTypeCheck = function(option) { | ||
if (Array.isArray(option)) return isLimPrim(option[0]) ? 'array' : false; | ||
else return isLimPrim(option) ? 'lim-prim' : 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.
what is lim-prim
?
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.
a subset of primitives -> number and string
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 is the output polymorphic?
this.handleChecked(idx); | ||
onChange(e); | ||
}} | ||
placeholder={placeholder} |
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 might be reading this wrong but wouldn't this mean that all radios will have the same placeholder? Also, do radio inputs have placeholders?
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.
Radio does not have a placeholder to my knowledge.
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.
If this component is going to be exclusively for Radio then this should be removed imo.
I will be adding object compatibility in the next refactor. |
|
this.handleChecked(idx); | ||
onChange(e); | ||
}} | ||
placeholder={placeholder} |
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.
If this component is going to be exclusively for Radio then this should be removed imo.
}} | ||
placeholder={placeholder} | ||
style={style} | ||
type={type} |
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.
following on the previous comment, if this is specifically a Radio input, shouldn't type be hard coded? We should harden on either having flexible, general inputs or having the specific type. My guess is this could allow for someone to do <Radio type="number" {...otherProps} />
and use a radio component to render a non radio input.
Agreed. I’m going to refactor the structure of input and typing on this
component. Ultimately I see it as a Select component with options for
“radio”, “toggle” and “drop down”. If there is another “select one” type
I’m not thinking of, please comment.
Thoughts? @bucko13 @tynes
…On Fri, Aug 10, 2018 at 10:16 Buck Perley ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/components/Input/Type/Radio.js
<#15 (comment)>:
> + const radioType = optTypeCheck(option);
+ const optLabel = radioType === 'lim-prim' ? option : option[0];
+ const optValue = radioType === 'lim-prim' ? option : option[1];
+
+ return (
+ <div key={`${optLabel}-${idx}`} className={className}>
+ <label className={`form-label ${theme.input.capitalize}`}>
+ <input
+ checked={idx === this.state.checked}
+ className={theme.input[type]}
+ name={`${name}`}
+ onChange={e => {
+ this.handleChecked(idx);
+ onChange(e);
+ }}
+ placeholder={placeholder}
If this component is going to be exclusively for Radio then this should be
removed imo.
------------------------------
In src/components/Input/Type/Radio.js
<#15 (comment)>:
> + const optValue = radioType === 'lim-prim' ? option : option[1];
+
+ return (
+ <div key={`${optLabel}-${idx}`} className={className}>
+ <label className={`form-label ${theme.input.capitalize}`}>
+ <input
+ checked={idx === this.state.checked}
+ className={theme.input[type]}
+ name={`${name}`}
+ onChange={e => {
+ this.handleChecked(idx);
+ onChange(e);
+ }}
+ placeholder={placeholder}
+ style={style}
+ type={type}
following on the previous comment, if this is specifically a Radio input,
shouldn't type be hard coded? We should harden on either having flexible,
general inputs or having the specific type. My guess is this could allow
for someone to do <Radio type="number" {...otherProps} /> and use a radio
component to render a non radio input.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#15 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AR3NqH6pnZnsMo69G7xHV4pxtG6tWGTHks5uPb_dgaJpZM4Vy_Xw>
.
|
Yeah, I think have more flexible (and better designed) selector components is a good idea. For what it's worth, this is an example of a design we have for the currently in progress wallet plugin. As you can see it has a pretty custom radio-like input: Regarding a dropdown, just FYI, @tynes recently added this: https://github.com/bpanel-org/bpanel-ui/blob/master/src/components/Dropdown/Dropdown.js |
We could map an object of label : value pairs, tuples, or strings as
children.
React doesn’t like objects as child nodes which is why I implemented tuples
but we can easily add a data property.
I’ll look at the data handling patterns in other components and work on a
better design. I whipped this up to troubleshoot our state handling on the
previous radio.
…On Fri, Aug 10, 2018 at 10:31 Benjamin olki ***@***.***> wrote:
Agreed. I’m going to refactor the structure of input and typing on this
component. Ultimately I see it as a Select component with options for
“radio”, “toggle” and “drop down”. If there is another “select one” type
I’m not thinking of, please comment.
Thoughts? @bucko13 @tynes
On Fri, Aug 10, 2018 at 10:16 Buck Perley ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In src/components/Input/Type/Radio.js
> <#15 (comment)>:
>
> > + const radioType = optTypeCheck(option);
> + const optLabel = radioType === 'lim-prim' ? option : option[0];
> + const optValue = radioType === 'lim-prim' ? option : option[1];
> +
> + return (
> + <div key={`${optLabel}-${idx}`} className={className}>
> + <label className={`form-label ${theme.input.capitalize}`}>
> + <input
> + checked={idx === this.state.checked}
> + className={theme.input[type]}
> + name={`${name}`}
> + onChange={e => {
> + this.handleChecked(idx);
> + onChange(e);
> + }}
> + placeholder={placeholder}
>
> If this component is going to be exclusively for Radio then this should
> be removed imo.
> ------------------------------
>
> In src/components/Input/Type/Radio.js
> <#15 (comment)>:
>
> > + const optValue = radioType === 'lim-prim' ? option : option[1];
> +
> + return (
> + <div key={`${optLabel}-${idx}`} className={className}>
> + <label className={`form-label ${theme.input.capitalize}`}>
> + <input
> + checked={idx === this.state.checked}
> + className={theme.input[type]}
> + name={`${name}`}
> + onChange={e => {
> + this.handleChecked(idx);
> + onChange(e);
> + }}
> + placeholder={placeholder}
> + style={style}
> + type={type}
>
> following on the previous comment, if this is specifically a Radio input,
> shouldn't type be hard coded? We should harden on either having flexible,
> general inputs or having the specific type. My guess is this could allow
> for someone to do <Radio type="number" {...otherProps} /> and use a
> radio component to render a non radio input.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#15 (review)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AR3NqH6pnZnsMo69G7xHV4pxtG6tWGTHks5uPb_dgaJpZM4Vy_Xw>
> .
>
|
Only the label is actually being used as a child, the rest would be props, which works fine for the object structure. The label could then just be pulled out of each object as you map through them. The problem with the tuple is that implementers have to know the right order to add the options in. |
That’s very close to what I have in the next version following the buttons
pattern.
…On Fri, Aug 10, 2018 at 10:36 Buck Perley ***@***.***> wrote:
Yeah, I think have more flexible (and better designed) selector components
is a good idea.
For what it's worth, this is an example of a design we have for the
currently in progress wallet plugin. As you can see it has a pretty custom
radio-like input:
[image: screen shot 2018-08-10 at 10 34 06 am]
<https://user-images.githubusercontent.com/4344978/43972436-37cd50e0-9c89-11e8-83c2-29858bdaf9cc.png>
Regarding a dropdown, just FYI, @tynes <https://github.com/tynes>
recently added this:
https://github.com/bpanel-org/bpanel-ui/blob/master/src/components/Dropdown/Dropdown.js
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#15 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AR3NqKuOapi-8TLSlI5Zjfi30IDzCItnks5uPcS1gaJpZM4Vy_Xw>
.
|
Awesome, let’s just implement that from the get go then. The tuples just seem too brittle to me. Doesn’t seem worth it to have to continue supporting them when an object works so much better.
… On Aug 10, 2018, at 10:50 AM, Benjamin ***@***.***> wrote:
That’s very close to what I have in the next version following the buttons
pattern.
On Fri, Aug 10, 2018 at 10:36 Buck Perley ***@***.***> wrote:
> Yeah, I think have more flexible (and better designed) selector components
> is a good idea.
>
> For what it's worth, this is an example of a design we have for the
> currently in progress wallet plugin. As you can see it has a pretty custom
> radio-like input:
> [image: screen shot 2018-08-10 at 10 34 06 am]
> <https://user-images.githubusercontent.com/4344978/43972436-37cd50e0-9c89-11e8-83c2-29858bdaf9cc.png>
>
> Regarding a dropdown, just FYI, @tynes <https://github.com/tynes>
> recently added this:
> https://github.com/bpanel-org/bpanel-ui/blob/master/src/components/Dropdown/Dropdown.js
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#15 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AR3NqKuOapi-8TLSlI5Zjfi30IDzCItnks5uPcS1gaJpZM4Vy_Xw>
> .
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#15 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AEJMktwMUuOvIAlw7E7Req7b72jyFdo3ks5uPcfOgaJpZM4Vy_Xw>.
|
Fixes #14