-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Improve documentation for ListItem
and ListItemSecondaryAction
#13916
Comments
|
This is one of the worst pain points I've encountered in MUI... I was encountering crazy back-and-forth scroll behavior with a Essentially, to use a component that renders a
I fully understand that supporting the base case, the button case, and the custom component case may require some ugly tradeoffs. But I ended up making this workaround component...not completely sure how I feel about it. I might even make it a global component override. /**
* @flow
* @prettier
*/
import * as React from 'react'
import ListItem from '@material-ui/core/ListItem'
import { isMuiElement } from '@material-ui/core/utils'
export type Props = {
+children?: any,
+style?: ?Object,
+ContainerProps?: ?Object,
}
/* eslint-disable react/display-name */
const VirtualizedListItem = React.forwardRef(
(
{ children: childrenProp, style, ContainerProps, ...props }: Props,
ref: React.ElementRef<any>
): React.Node => {
const children = React.Children.toArray(childrenProp)
const hasSecondaryAction =
children.length &&
isMuiElement(children[children.length - 1], ['ListItemSecondaryAction'])
return (
<ListItem
{...props}
ref={ref}
ContainerProps={
hasSecondaryAction
? {
...ContainerProps,
style: { ...ContainerProps?.style, ...style },
}
: ContainerProps
}
style={hasSecondaryAction ? { height: style?.height } : style}
>
{children}
</ListItem>
)
}
)
export default VirtualizedListItem |
I believe we have another open issue dedicated to this topic (labeled breaking change). The best solution is likely to introduce a new component, to keep the user API close to the underlying DOM structure. |
See #13597 |
Okay great! I didn't manage to find that. Yeah a new component was one potential solution I had in mind. |
Improve the documentation for how
ListItemSecondaryAction
components work withinListItem
components.Expected Behavior 🤔
The documentation would have warnings / implementation details indicating the following:
ListItemSecondaryAction
must be the last child ofListItem
forListItem
to detect it has a secondary action (see source code).ListItemSecondaryAction
, themuiName
field must be set to'ListItemSecondaryAction'
(see code above and issue Cannot use wrapper for ListItemSecondaryAction #11622).ListItemSecondaryAction
within aListItem
, the component used for theListItem
changes (see issue [List] Improve ListItemSecondaryAction handling #13597).These would be useful at the top of the API documentation for ListItemSecondaryAction and possibly ListItem.
Current Behavior 😯
These behaviors are undocumented and require hunting through the issues and the code to figure out.
Context 🔦
I spent all morning trying to figure out why when I hovered or clicked on my secondary action, it also triggered the list item. I finally figured out it was the order of the children after looking at the code. I was also using a wrapper for
ListItemSecondaryAction
, which had to be fixed too.My use case is that I wanted the secondary action on the left side, not the right side. So I had changed the order of the children, not thinking that just changing the order would affect the behavior of
ListItem
.Long-term, the best solution would be to improve the implementation so secondary actions are not so fragile. But I understand there may be other priorities right now.
One possibility to explore for a future API is to have the secondary action passed in via a
secondaryActionComponent
prop. Then theListItem
would always know whether a secondary action existed and could wrap it within aListItemSecondaryAction
internally.The text was updated successfully, but these errors were encountered: