Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

terrapanda
Copy link
Contributor

@terrapanda terrapanda commented Aug 7, 2018

  • Fix Radio Checked Onchange
  • Change Input to Switch Case Render
  • Pull Special Case Types from ./Type i.e. Radio

Fixes #14

);
switch (type) {
case 'radio':
return <Radio {...this.props}>{children}</Radio>;
Copy link
Contributor

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 👍

} = this.props;

return children.map((option, idx) => (
<div key={option} className={className}>
Copy link
Contributor

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...

@terrapanda
Copy link
Contributor Author

terrapanda commented Aug 8, 2018 via email

@bucko13
Copy link
Contributor

bucko13 commented Aug 8, 2018

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.

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 👍

@terrapanda
Copy link
Contributor Author

Radio Input update complete.

Edge case to consider when implementing Form wrapper is that names of inputs must be unique.

Demo:

<form>
  <Input type="radio" name="unique" onChange={function(e) {}}>
    {['yes', 'no', ['maybe', 'any value']]}
  </Input>
</form>

@terrapanda
Copy link
Contributor Author

Improve option handling with tuple and string compatability:

['label', 'label'] [['label', 'any value'], ['label', 'any value']]

Copy link
Contributor

@bucko13 bucko13 left a 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is lim-prim?

Copy link
Contributor Author

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

Copy link
Contributor

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}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@terrapanda
Copy link
Contributor Author

I will be adding object compatibility in the next refactor.

@bucko13
Copy link
Contributor

bucko13 commented Aug 10, 2018

I will be adding object compatibility in the next refactor.
Is there a reason to change the passed prop format a second time? I feel like if we're taking the time to refactor now, we should just implement the format we intend to use from the get go. Otherwise we'll have to support the old as well as the new and make changes to BUI again too.

this.handleChecked(idx);
onChange(e);
}}
placeholder={placeholder}
Copy link
Contributor

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}
Copy link
Contributor

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.

@terrapanda
Copy link
Contributor Author

terrapanda commented Aug 10, 2018 via email

@bucko13
Copy link
Contributor

bucko13 commented Aug 10, 2018

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:
screen shot 2018-08-10 at 10 34 06 am

Regarding a dropdown, just FYI, @tynes recently added this: https://github.com/bpanel-org/bpanel-ui/blob/master/src/components/Dropdown/Dropdown.js

@terrapanda
Copy link
Contributor Author

terrapanda commented Aug 10, 2018 via email

@bucko13
Copy link
Contributor

bucko13 commented Aug 10, 2018

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.

@terrapanda
Copy link
Contributor Author

terrapanda commented Aug 10, 2018 via email

@bucko13
Copy link
Contributor

bucko13 commented Aug 10, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants