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

[RadioButtonGroup] Enable handling of non-RadioButton children #3627

Closed
wants to merge 1 commit into from

Conversation

bshyong
Copy link

@bshyong bshyong commented Mar 7, 2016

When nesting children that are not RadioButtons in the RadioButtonGroup, the non-RadioButton elements are ignored.

The following example generates unexpected behavior. All non-RadioButton components are ignored.

Source code:

<RadioButtonGroup>
  <div className="col6">
    <RadioButton />
  </div>
  <div className="col6">
    <RadioButton />
  </div>
</RadioButtonGroup>

Rendered output:

<RadioButtonGroup>
    <RadioButton />
    <RadioButton />
</RadioButtonGroup>

Resolves #2225

...option,
props: {
...option.props,
children: React.Children.map(option.props.children, this.radioButtonMapFunc, this)
Copy link
Member

Choose a reason for hiding this comment

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

this._radioButtonMapFunc

or rather, rename _radioButtonMapFunc to radioButtonMapFunc

@mbrookes mbrookes changed the title [RadioButtonGroup] Enable handling of non-RadioButton children; resolves #2225 [RadioButtonGroup] Enable handling of non-RadioButton children Mar 8, 2016
@mbrookes
Copy link
Member

mbrookes commented Mar 8, 2016

@bshyong Please could you also update the commit title to match the PR title? (Helps keep the commit history clean).

@mbrookes mbrookes added bug 🐛 Something doesn't work PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 8, 2016
@bshyong
Copy link
Author

bshyong commented Mar 8, 2016

Hi guys, thank you for reviewing! I've made the requested changes.

@mbrookes mbrookes added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 8, 2016
@alitaheri
Copy link
Member

This does fix the issue for now. But I think this should be contextual to avoid recursive calls on each render. recursion is heavy stuff. But I'm still ok with it as there won't usually be a lot of nested stuff in a radio button group. 👍

@callemall/material-ui Guys take a look please 👍

@mbrookes
Copy link
Member

mbrookes commented May 7, 2016

@alitaheri

I think this should be contextual to avoid recursive calls on each render

Could you explain? Thanks.

@alitaheri
Copy link
Member

@mbrookes What I mean is, this implementation recursively walks down the tree to find the RadioButtons which is much more expensive than providing a context with RadioButtonGroup and having it passed down to RadioButton so that they can register themselves as members of that group.

@mbrookes
Copy link
Member

mbrookes commented May 7, 2016

@alitaheri Thanks. 👍 @bshyong Are you happy to update this PR with that approach?

@mbrookes mbrookes added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels May 7, 2016
@bshyong
Copy link
Author

bshyong commented May 7, 2016

Hey guys,

I just looked through the code; I'm not sure I understand the context
approach. It seems to me that we need to access every child anyways to
preserve the structure. React.Children.map only maps over immediate
children
so I wrote a map function that looks for RadioButtons within
non-RadioButton children and renders them out as well.

Wonder if I am missing something here or if one of you can provide some
pseudo code to better illustrate using a context?

Ben Shyong
909-274-9664

On Sat, May 7, 2016 at 7:04 AM, Matt Brookes notifications@github.com
wrote:

@alitaheri https://github.com/alitaheri Thanks. 👍 @bshyong
https://github.com/bshyong Are you happy to update this PR with that
approach?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#3627 (comment)

@alitaheri
Copy link
Member

@bshyong Well the idea is, we reverse the flow of control. instead of RadioButtonGroup looking for it's RadioButtons, the RadioButtons register themselves via the hook e.g. this.context.registerRadioButton(this, value) which will then put this RadioButton into the list of RadioButtons that that group controls. If that still doesn't make sense, then maybe this approach is over engineering, and must be avoided for the sake of maintainability. But this solution performs better, though that might be irrelevant since not so many items would show up inside a group anyway.

@bshyong
Copy link
Author

bshyong commented May 8, 2016

That sounds like a clever approach. I'll need to find some time to look at
this again to see how to implement this.

Ben Shyong
909-274-9664

On Sat, May 7, 2016 at 10:43 AM, Ali Taheri Moghaddar <
notifications@github.com> wrote:

@bshyong https://github.com/bshyong Well the idea is, we reverse the
flow of control. instead of RadioButtonGroup looking for it's
RadioButtons, the RadioButtons register themselves via the hook e.g. this.context.registerRadioButton(this,
value) which will then put this RadioButton into the list of RadioButtons
that that group controls. If that still doesn't make sense, then maybe this
approach is over engineering, and must be avoided for the sake of
maintainability. But this solution performs better, though that might be
irrelevant since not so many items would show up inside a group anyway.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#3627 (comment)

@nathanmarks
Copy link
Member

Closing this as there is no movement.

@sakulstra sakulstra mentioned this pull request Sep 13, 2017
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants