Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/data/material/components/table/CollapsibleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ function createData(name, calories, fat, carbs, protein, price) {
function Row(props) {
const { row } = props;
const [open, setOpen] = React.useState(false);
const detailsId = React.useId();

return (
<React.Fragment>
<TableRow sx={{ '& > .MuiTableCell-root': { borderBottom: 'unset' } }}>
<TableCell>
<IconButton
aria-label="expand row"
aria-label={open ? 'collapse row' : 'expand row'}
aria-expanded={open}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's also add aria-controls pointing to the row element which is controlled by this button.

aria-controls={detailsId}
size="small"
onClick={() => setOpen(!open)}
>
Expand All @@ -61,7 +64,7 @@ function Row(props) {
<TableCell align="right">{row.carbs}</TableCell>
<TableCell align="right">{row.protein}</TableCell>
</TableRow>
<TableRow>
<TableRow id={detailsId} aria-hidden={!open ? true : undefined}>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
<Collapse in={open} timeout="auto" unmountOnExit>
<Box sx={{ margin: 1 }}>
Expand Down
7 changes: 5 additions & 2 deletions docs/data/material/components/table/CollapsibleTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ function createData(
function Row(props: { row: ReturnType<typeof createData> }) {
const { row } = props;
const [open, setOpen] = React.useState(false);
const detailsId = React.useId();

return (
<React.Fragment>
<TableRow sx={{ '& > .MuiTableCell-root': { borderBottom: 'unset' } }}>
<TableCell>
<IconButton
aria-label="expand row"
aria-label={open ? 'collapse row' : 'expand row'}
aria-expanded={open}
aria-controls={detailsId}
size="small"
onClick={() => setOpen(!open)}
>
Expand All @@ -67,7 +70,7 @@ function Row(props: { row: ReturnType<typeof createData> }) {
<TableCell align="right">{row.carbs}</TableCell>
<TableCell align="right">{row.protein}</TableCell>
</TableRow>
<TableRow>
<TableRow id={detailsId} aria-hidden={!open ? true : undefined}>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
<Collapse in={open} timeout="auto" unmountOnExit>
<Box sx={{ margin: 1 }}>
Expand Down
Loading