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

Recursively extending child in selectable list for nested lists #2320

Merged
merged 1 commit into from
Dec 29, 2015

Conversation

gobadiah
Copy link
Contributor

I'm using the selectable enhancer on a nested list, but for now only top ListItem can be selected.

With this pull request, we recursively modify children and their nestedItems props to make every ListItem selectable.

This is my first pull request so I may be doing this wrong, any advise would be gladly taken.

Thanks !

@oliviertassinari
Copy link
Member

@gobadiah Looks good to me. Could you fix the travis task?
@frankf-cgn Could you review this too?

@gobadiah
Copy link
Contributor Author

Yep, done.

@@ -65,7 +65,7 @@ export const SelectableContainerEnhance = (Component) => {
};
}

listItems = React.Children.map(children, (child) => {
function extendChild(child) {
Copy link
Member

Choose a reason for hiding this comment

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

If we can, could you move this method outside the render method?
That's going to be better for perf. We don't want this to be allocated at each rendering.

@oliviertassinari
Copy link
Member

@gobadiah Looks good now. I could merge it as it is 👍.
However, if you want this to be less likely to break in the future, I would recommend you to update the SelectableContacts example with this feature (that's not as good as a test, but still).
It would help to keep track of this.
And to be perfect, you can squash down the commit to keep a clean history.

@gobadiah
Copy link
Contributor Author

@oliviertassinari I've updated the example SelectableContacts. Just a remark:
If you select a nestedItem, and then "toggle" its parent, the nestedItem is still selected but no longer visible.
It seems to me this shouldn't be the normal behaviour, so maybe when that happens we should call requestChange props with null for example, or notify the user in some way.
In my case, the selectedItem plays an important role, so I have to watch toggle event, and search the tree to see if the selectedItem is now hidden, it must be easier to do this in the library.

@frankf-cgn
Copy link

@oliviertassinari @gobadiah So far looks good to me, too. But before merging, we should solve the toggle-issue mentioned by @gobadiah.
I have no immediate idea for a smart solution at the moment. (Re-)Setting the selectedItem because of the parent-toggle does not seem right to me. My first though on it is that it might be better to mark the parent somehow, indicating that tehre are hidden selected items. @gobadiah: What do you think? Is marking the toggleable parent an option?
If it helps, I could investigate on this on wednesday.

@gobadiah
Copy link
Contributor Author

gobadiah commented Dec 1, 2015

@frankf-cgn Tagging the parent listitem seems a viable option, though I have no idea how to do this "visually". I still think a user should be able to know when that happens, so he can respond according to his use case, by doing nothing, or maybe deselecting, or whatever.

@oliviertassinari
Copy link
Member

If you select a nestedItem, and then "toggle" its parent, the nestedItem is still selected but no longer visible.

I think that there are valid use cases for this.

(Re-)Setting the selectedItem because of the parent-toggle does not seem right to me.

I agree, for instance, have a look at the List menu on the left panel of https://material.angularjs.org/latest/.

But before merging, we should solve the toggle-issue mentioned by @gobadiah.

Well, I think that this PR is already valuable and that we are talking about a missing feature,
not about a wrong implemented feature. I'm gonna merge.

@gobadiah Thank!

oliviertassinari added a commit that referenced this pull request Dec 29, 2015
[List] Recursively extending child in selectable list for nested lists
@oliviertassinari oliviertassinari merged commit 7355635 into mui:master Dec 29, 2015
@zannager zannager added the component: list This is the name of the generic UI component, not the React module! label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: list This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants