-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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] Make semantically correct #15333
Conversation
@mbrookes For context, I have fought hard in the past with the list page to make https://validator.w3.org pass. I'm happy if we can simplify the logic. |
Sorry, I meant to make this a draft PR. |
It seems it doesn't like We could resolve the former by making ButtonBase a child of |
Should they be listed as items? We are displaying buttons or links in the example.
As far as I know, the browsers we support have full support for HTML5. Can we skip the usage of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be so glad to get rid of the implicit Button. Just create a ListItemButton
instead that nests li > button
properly.
<div role="listitem button" />
would work as well. <li role="button" />
is probably bad because it removes the listitem
role?
I'm kicking myself that I didn't bookmark it, but one article I referred to described how each of the major screen readers interprets
💯
Separate
Makes sense. Me:
The answer is: |
Create the separate
Well I don't mind adding the redundancy here. It's just an attribute and not multiple lines of code. But if this is an actual issue we should investigate the other html5 elements we use. |
Would it make thing simpler? Looking at the source, I believe that most of the complexity is in the secondary action logic. It's kind of a mess. We should optimize for the user experience. I don't think that the button property is that much an issue on its own. Alternatively, we could have people do For the secondary action problem, what do you think of this different API? <List className={classes.root}>
{[0, 1, 2, 3].map(value => (
<ListItemSecondaryAction action={
<IconButton edge="end" aria-label="Comments">
<CommentIcon />
</IconButton>
}>
<ListItem key={value} role={undefined} dense button onClick={handleToggle(value)}>
<ListItemIcon>
<Checkbox
edge="start"
checked={checked.indexOf(value) !== -1}
tabIndex={-1}
disableRipple
/>
</ListItemIcon>
<ListItemText primary={`Line item ${value + 1}`} />
</ListItem>
</ListItemSecondaryAction>
))}
</List> |
Funny enough, we are using the ListItem > Button strategy for the left side list menu of the documentation. |
I haven't looked into it. But even if it's just a thin wrapper I rather let people use |
This comment has been minimized.
This comment has been minimized.
d9d9c1c
to
1422d6c
Compare
1422d6c
to
f65dd3a
Compare
If we nest the button can we also use the native |
@eps1lon Done. I have also cleared out much of the cruft that had accumulated in ListItem. There was code to catch issues caused by code to... (you get the idea). I suspect many other components may have similar bloat... Anyway, while there is a slight tradeoff when providing props to ButtonBase (see SimpleList.js demo), the API is simpler overall, and the ListItem code much simpler. I have not attempted to align the tests or type definitions yet, pending approval of the general approach. |
84d48d8
to
6ebbafb
Compare
The issue is that you can't have block elements as the children of button. |
I meant li > button instead if li > div[role="button"] |
That's what it is currently, as of this commit c3e1986 per your comment here: #15333 (comment) However as I said here: #15333 (comment), the issue with
|
That was my question: Why do you need block content? But I guess we need it for the other ListItem* components. Which leads to the question: Should we use rather use inline elements for the ListItem* components? |
When did you ask that question? What you said was (not a question): "I meant Not only was this already implemented (in response to your prior suggestion), it's the very reason block content becomes a problem. This is what I was pointing out (twice).
Because some children (Avatar, MuiListItemSecondaryAction) are not inline.
Possibly. Some of them already are inline, but not sure how we'd deal with Avatar, short of creating a wrapper component. This is why I said (also twice): " |
@mbrookes I would propose that we come back to this problem when we start working on v5. From what I understand, it requires a breaking change. |
This is a discussion draft. I have only changed one demo so far, and it's still not perfect. The changes are:
Significantly simplify ListItem internals.
Use semantically correct lists to allow screen readers to enumerate the items.
Userole="navigation"
on thenav
:https://www.w3.org/WAI/tutorials/page-structure/regions/#accessupport
Use(Divider already adds this when<li role="separator">
for the Divider.component="li"
. Updated demos to be compliant.)Also, closes #15482