<List><ListItem>Item 1</ListItem><ListItem>Item 2</ListItem></List>
Prop | Type | Default | Description |
---|---|---|---|
children | node | The content of the component. | |
classes | object | Override or extend the styles applied to the component. See CSS API below for more details. | |
component | elementType | 'ul' | The component used for the root node. Either a string to use a HTML element or a component. |
dense | bool | false | If true, compact vertical padding designed for keyboard and mouse input will be used for the list and list items. The prop is available to descendant components as the dense context. |
disablePadding | bool | false | If true, vertical padding will be removed from the list. |
subheader | node | The content of the subheader, normally ListSubheader. |
The ref
is forwarded to the root element.
Any other props supplied will be provided to the root element (native element).
<><List component="nav" aria-label="main mailbox folders"><ListItem button><ListItemIcon><Add /></ListItemIcon><ListItemText primary="Inbox" /></ListItem><ListItem button><ListItemIcon><Mail /></ListItemIcon><ListItemText primary="Drafts" /></ListItem></List><Divider /><List component="nav" aria-label="secondary mailbox folders"><ListItem button><ListItemText primary="Trash" /></ListItem><ListItem button component="a" href="#simple-list"><ListItemText primary="Spam" /></ListItem></List></>
() => {const [open, setOpen] = React.useState(false);function handleClick() {setOpen((open) => !open);}return (<Listcomponent="nav"aria-labelledby="nested-list-subheader"subheader={<ListSubheader component="div" id="nested-list-subheader">Nested List Items</ListSubheader>}><ListItem button><ListItemIcon><Send /></ListItemIcon><ListItemText primary="Sent mail" /></ListItem><ListItem button><ListItemIcon><Goal /></ListItemIcon><ListItemText primary="Drafts" /></ListItem><ListItem button onClick={handleClick}><ListItemIcon><Mail /></ListItemIcon><ListItemText primary="Inbox" />{open ? <ArrowDown /> : <ArrowRight />}</ListItem><Collapse in={open} timeout="auto" unmountOnExit><List component="div" disablePadding><ListItem style={{ paddingLeft: '2rem' }} button><ListItemIcon><Notification /></ListItemIcon><ListItemText primary="Starred" /></ListItem></List></Collapse></List>);};
() => {const [checked, setChecked] = React.useState([1]);const handleToggle = (value) => () => {const currentIndex = checked.indexOf(value);const newChecked = [...checked];if (currentIndex === -1) {newChecked.push(value);} else {newChecked.splice(currentIndex, 1);}setChecked(newChecked);};return (<List dense>{[0, 1, 2, 3].map((value) => {const labelId = `checkbox-list-secondary-label-${value}`;return (<ListItem key={value} button><ListItemAvatar><Avataralt={`Avatar n°${value + 1}`}src={`/static/images/avatar/${value + 1}.jpg`}/></ListItemAvatar><ListItemText id={labelId} primary={`Line item ${value + 1}`} /><ListItemSecondaryAction><Checkboxedge="end"onChange={handleToggle(value)}checked={checked.indexOf(value) !== -1}inputProps={{ 'aria-labelledby': labelId }}/></ListItemSecondaryAction></ListItem>);})}</List>);};