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

[ListItem] Improve ListItemSecondaryAction DX #14350

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Jan 30, 2019

  • Adds a warning if ListItemSecondaryAction is not the last child of a ListItem
  • Adds documentation for the warning
  • Improve container component docs

Closes #13916

@eps1lon eps1lon added docs Improvements or additions to the documentation component: list This is the name of the generic UI component, not the React module! labels Jan 30, 2019
@eps1lon eps1lon force-pushed the feat/core/ListItemSecondaryAction/improve-dx branch from c001c7b to 42bbcdc Compare January 30, 2019 11:56
children: chainPropTypes(PropTypes.node, props => {
const children = React.Children.toArray(props.children);

// React.Children.toArray(props.children).findLastIndex(isListItemSecondaryAction)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this?

Copy link
Member

Choose a reason for hiding this comment

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

What about .findIndex() and replace it once we drop IE 11?

Copy link
Member

Choose a reason for hiding this comment

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

I was just asking about the commented out code :) The below code looks okay to me

Copy link
Member

@oliviertassinari oliviertassinari Jan 30, 2019

Choose a reason for hiding this comment

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

Yeah. I agree, I would leave something about IE 11 so we don't forget to refactor the code, in 1-2 years from now.

Copy link
Member Author

Choose a reason for hiding this comment

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

comment explains the intent of the code

Copy link
Member Author

Choose a reason for hiding this comment

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

But with <ListItem><Action /><Text /><Action /></ListItem> ListItem is correctly detecting that it has a secondary action.

https://github.com/mui-org/material-ui/blob/578ba6ec1b5a90a27c140b62ffb1248fc4f71672/packages/material-ui/src/ListItem/ListItem.js#L110-L112

Displaying this warning would not be correct with that markup. I fail to see the value in discussing this implementation detail that would add false positives to the warning message. If you want an additional warning against multiple Actions then I'm happy to add it. Your proposal implies one step forward and one step back for DX.

Copy link
Member

@oliviertassinari oliviertassinari Jan 31, 2019

Choose a reason for hiding this comment

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

<ListItem><Action /><Text /><Action /></ListItem> is invalid. The existing warning is good enough IMHO to start with minimal overhead. We can refine it later. At least, we would have data (optimize for learning). If we don't do this change, people will nest two buttons. From a user perpective, it will look like this: "the action should be the last child. Wtf it's already the last child. Oh but I have another action, OK it should be the last child too. Wait, I can only have one child. Ok so I can only use one action."

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if React don't already warn about button > button. It would just add another hint.

Copy link
Member

@oliviertassinari oliviertassinari Jan 31, 2019

Choose a reason for hiding this comment

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

Anyway, it's up to you. It's not truly important. We shouldn't invest too much time here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wait, I can only have one child

You're making my argument here. The current warning with your implementation proposal would not warn about "multiple children detected". It would create exactly the scenario you described.

We never warned explicitly about multiple actions. I don't know of any issue that described confusion about multiple actions. Maybe people are already using multiple actions just fine. If you want to warn against multiple actions feel free to open a separate PR.

@oliviertassinari oliviertassinari merged commit 5572b13 into mui:master Jan 31, 2019
@eps1lon eps1lon deleted the feat/core/ListItemSecondaryAction/improve-dx branch January 31, 2019 13:32
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! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants