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
Input WIP #89
Input WIP #89
Conversation
Great stuff! No comments from me at the moment, it all looks spot on. |
This is looking really good! A thought i had when looking at this is i wonder if it might also be a good idea for the var big$$$Input = <Input type={<FancyAutoGrowTextInput />} addonBefore="$" /> Probably would need to use Im happy to do a code review if you feel like the code is in a place where that would be helpful. |
Thanks, I was working on it just now. (I see you're in NZ too, yay for 3 day weekends!) My idea was to have a 'custom' type and render props.children inside the wrappers. In either case, passing in arbitrary components could break getValue and other features but I think this is really useful in abstracting away bootstrap's form-group, label & input wrapper boilerplate. In my case I want to render a date range which is two inputs inside an input-group.
Would using cloneWithProps be safe in this case? What about if there are multiple children? |
Thinking about it more, maybe it would be better renamed as FormGroup. Rendering children is the default but other elements are rendered as a convenience if type, label, wrapper etc are provided. This would support any of the following uses:
However, this would make using Yeah, better off as input, thats what we really care about. |
3 day weekends rock, i knew the queen was good for something :) You in Auckland?
You would want to use
I was thinking about this too, i seems like a good idea to remove the For example, the <DateRange fromDate="..." value={value} onChange={handleChange} />
Here are some thoughts i had on the different API's: // 1
<Input type="custom" label="Date:">
<DateRange ref="date" fromDate="...">
</Input>
// 2
<Input type={<DateRange ref="date" fromDate="...">} label="Date:" />
// 3
<FormGroup>
<label>Text:</label>
<DateRange ref="date" fromDate="...">
</FormGroup>
|
Yes, I'm in Auckland. I agree I don't think manipulating children is good practice. In the date range case, there are actually two values (from & to). Trying to get Input to handle this through getValue doesn't sound like fun. Instead I think components should be managed wherever they are created. If you want to use a special component inside the Input wrappers, you should be entirely responsible for it. Because Input will use transferPropsTo on it's internal input/select/textarea, it should cover 90% of use cases without needing to pass in components. In the edge cases, Input should allow use as wrapper.
Could your FancyAutoGrowTextInput case work this way? |
Yeah that makes sense, would definitely work for the use cases i was thinking of. I see what you were saying earlier about the // 90% use case
<Input type="text" label="Text:" value={...} onChange={...} />
// Special case, used as wrapper only
<FormGroup label="Text:">
<input value={...} onChange={...} />
<input value={...} onChange={...} />
...
</FormGroup> The two use cases actually have very different API's, and this might help make it clearer, Just a thought otherwise the previous API you stated sounds good. |
This is the current API: <Input
type="text" // Any HTML input type as well as select, textarea & static.
label="Text:" // Rendered in label element.
help="Enter text." // Rendered in .help-block span.
addonBefore="$" // Rendered in input-group.
addonAfter=".00" // Rendered in input-group.
bsStyle="warning" // One of success, warning or error. Adds validation classes.
hasFeedback={true} // Renders validation icon.
groupClassName="group"
wrapperClassName="wrapper"
labelClassName="label"
// All properties are applied to the final input/select/textarea/p element using transferPropsTo.
/>
// Children are rendered for type=select...
<Input type="select">
<option value="1">
<option value="2">
</Input>
// or if no type specified (used as a wrapper only).
<Input label="..." wrapperClassName="...">
<img src="...">
</Input> |
I don't think it's worth splitting out because checkbox & radio require different layouts, meaning only the outer form-group div can be separated. What about if we did it the other way around.
|
This is looking really good. I see what you mean about the |
Yeah, sorry for the lack of input from me. Looks great guys. |
I'm happy with this. Do you want me to rebase/squash the commits? |
// This could also be done using ReactLink: | ||
// http://facebook.github.io/react/docs/two-way-binding-helpers.html | ||
this.setState({ | ||
value: this.refs.input.getValue() |
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 isn't currently supported; it should be this.refs.input.getDOMNode().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.
Er, never mind 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.
This uses the new Input
component which has a getValue
method, not the React input
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.
Yeah, sorry about that. :) (It's actually likely that React's input
will support getValue
too but it doesn't today.)
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.
No worries :)
Added Checked is handled differently to value but we could support both as a convenience, like I did with the static type. Is it worth the effort? Are there any disadvantages? |
I think what you have looks really good, with how it is currently you still have the option to pull the value out of the field if you need it. Squashing the commits would be good, then we can get @stevoland to merge :) |
This is so great, thanks! Just one style point, could you replace the Thanks again! |
Closes #20
@stevoland Done |
@liamcmitchell Awesome, thanks. |
Work in progress:
Comments welcome.