-
Notifications
You must be signed in to change notification settings - Fork 54
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
Render checkbox on consumer side #14
Comments
@leonderijke I can clearly see how this would be a problem for you. Before saying yes or no let me think about it and see if I can find a solution. If you have any solution to suggest please feel free to do it as well. Meanwhile you should still be able to use the Thanks for your feedback! |
@leonderijke for the bootstrap usecase, would it be enough to enable a custom |
Here's an example: /**
* Example
* CheckboxGroup is provided by react-checkbox-group v0.3.2
* Checkbox is provided by react-bootstrap v0.29.x
*/
<CheckboxGroup name="fruits" value={this.props.activeFruits}>
{this.props.fruits.map(fruit => (
<Checkbox key={fruit._id} value={fruit._id}>{fruit.name}</Checkbox>
)}
</CheckboxGroup> The My current workaround is to mimic <CheckboxGroup name="groups" ref={ref => this.groups = ref} defaultValue={this.props.active} onChange={this._handleChange}>
{this._renderGroupRows}
</CheckboxGroup>
/**
* Renders the checkboxes for the groups
*
* @param {Component} Checkbox Checkbox component provided by `react-checkbox-group`
*/
_renderGroupRows(Checkbox) {
// Note: rendering Bootstrap HTML by hand here, because `react-bootstrap` and `react-checkbox-group` aren't compatible, in that they both want to output the checkbox
return (
<div>
{this.props.groups.map(group => (
<div className="checkbox" key={group._id}>
<label><Checkbox value={group._id} />{group.name}</label>
</div>
))}
</div>
);
} |
@leonderijke there seems to be a few issues on the react bootstap github mentioning the possibility of a CheckboxGroup: react-bootstrap/react-bootstrap#342 Have you looked at the possibility of creating a CheckboxGroup specifically for react-bootstrap? Since there is some interest, it could be a good opensource contribution :) What do you think? |
Before Besides React Bootstrap's Checkbox, I can imagine people wanting to use a custom Checkbox component for rendering the checkboxes. Is that a use case you want to support (in a future release)? For example, in It would be very nice if React Checkbox Group would remain interoperable with other libraries in the React ecosystem, instead of creating a specific Checkbox Group for these projects. |
@leonderijke I see what you mean, and I'm not sure what to answer. The reason why I switched up the model is because the previous version was doing way too many DOM manipulations, and they turned out to be shaky in some of my projects. If version < 1.0 is working well for you, there is nothing wrong with keeping it. If it turns out that a new version of React breaks it for any reason, I can fix it :) What do you think of this? |
@leonderijke as I was typing this I also thought of a new possibility, to let the user provide their own checkbox function. I'll be looking into it as an alternative. |
Providing our own checkbox function sounds like a good alternative to me. Let me see if I understand this correctly: The checkbox function takes the This gets me thinking about another possibility: use a Higher Order Component to pass I'll try to create a little proof of concept, to see if this makes sense. |
I like the HOC idea :) Let's see if we can do anything with it Ziad Saab Full-Stack Web Developer Instructor / Head of Education On Fri, Jun 10, 2016 at 7:41 AM, Leon de Rijke [email protected]
|
Ok, I have an early version working like this:
Example code: const CustomCheckbox = (props) => (
<input type="checkbox" {...props} className="my-custom-checkbox" />
);
<CheckboxGroup name="fruit" componentClass={CustomCheckbox}>
{
Checkbox => (
<div>
<Checkbox value="kiwi"/>
<Checkbox value="watermelon"/>
</div>
)
}
</CheckboxGroup> The A lot of What do you think? If this sounds good to you, I'll create a PR. |
@leonderijke thanks a lot for taking the time to work on this with me. At this time, I've decided to make this component match the API of the react-radio-group component to avoid any confusion when using them both on a project. |
I'm unclear what this final comment means as I don't use react-radio-group, have you decided to leave this functionality out completely? I would find it incredibly useful to be able to pass in a render function to render each individual checkbox. |
Before
1.0
we were able to render the checkboxes ourselves and pass them as children toCheckboxGroup
. I successfully used this in conjunction withreact-bootstrap
, wherereact-bootstrap
would render the checkboxes.Since
1.0
it is mandatory to use theCheckbox
component to render the checkboxes. Are you planning to support rendering without theCheckbox
component as well?The text was updated successfully, but these errors were encountered: