List
A list shows a set of rows, each with a line of text and optionally an icon, a second line, and something at the end.
A list shows a set of similar things people scan, pick from, or open: providers to log in with, menu options, the devices in an area. Every row has the same structure, so the eye can run down the left edge and find what it needs.
A list is built from two parts. Pick the container by what the list means, then the row by what it does:
- Containers:
ha-list-basefor a plain list,ha-list-selectablefor a list people pick from, andha-list-navfor a list of links. - Rows:
ha-list-item-basefor a row that only shows information,ha-list-item-buttonfor a row that does something, andha-list-item-optionfor a row people pick.
Use a list for:
- A set of similar items that people scan, pick from, or open
- Navigation to the next level, with a chevron at the end of each row
- Rows that only show information, like a value or a message
Don't use a list for:
- Actions on one item. Put them in a dropdown.
- Picking one option from a few that need explaining. Use a select box.
- Content that people show and hide. Use an expansion panel.
- List: the container. It has no padding of its own.
- Row: one item of the list
- Start: optional, an icon, image, or avatar at the start of the row
- Headline: the main text of the row
- Supporting text: optional, a short detail below the headline
- End: optional, content at the end, like a chevron, a short value, or a button
Start with the text, then add only what helps people recognize a row:
- An icon at the start.
- A supporting text, for a short detail, like a state or a description.
- Something at the end, like a chevron when the row opens something, or a short value.
ha-list-item-base is a row that does nothing when selected, like a row that only shows a value or a message. It has no ripple and no keyboard focus. Set interactive to put it in the keyboard navigation of the list anyway, like for a row people can sort.
ha-list-item-button opens something or runs an action. With an href, it renders a link, otherwise a button. The whole row is the target.
In ha-list-selectable, the rows are ha-list-item-option. The list owns the selection: people pick one option, or several with multi.
The default appearance, line, highlights the selected row. With appearance="checkbox", the row shows a checkbox, at the start or, with selection-position="end", at the end.
ha-list-nav wraps the list in a <nav> landmark, for a list of places people go to. Its rows are ha-list-item-button with an href. Give it a name with aria-label, so people can tell the landmarks of a page apart.
- Hover and pressed: a row that does something, or that people pick, shows a ripple.
- Focus: one row at a time is in the tab order. The arrow keys move focus between the rows. The focused row gets an outline in the focus color and a light background.
- Selected: in
lineappearance, the selected row gets a primary tint, and its text turns to the primary color. Incheckboxappearance, the checkbox shows the state. - Disabled: the text turns to the disabled text color, and the row can't be selected or focused.
- Long text: the headline and the supporting text are cut off with an ellipsis when they don't fit.
- Focus outside the list: with
virtual-focus, focus stays in another element, like the search field of a picker. The list marks the row the keyboard points at withactive, and scrolls it into view.
| Property | Value | Token |
|---|---|---|
| Row height, minimum | 48px | --ha-row-item-min-height |
| Padding top and bottom of a row | 12px | --ha-row-item-padding-block |
| Padding left and right of a row | 16px | --ha-row-item-padding-inline |
| Space between start, text, and end | 16px | --ha-row-item-gap |
| List padding | 0 | --ha-list-padding |
| Space between rows | 0 | --ha-list-gap |
| Headline font size | 14px | --ha-font-size-m |
| Supporting text font size | 12px | --ha-font-size-s |
| Supporting text color | Secondary text color | --secondary-text-color |
| Disabled text color | #bdbdbd in the light theme, #6f6f6f in the dark theme |
--disabled-text-color |
| Focus outline | 2px, in the focus color | --ha-list-item-focus-width |
Selected background, line appearance |
Primary tint | --ha-list-item-selected-background |
See UI text for how to write labels.
| Key | Action |
|---|---|
| Tab | Moves focus into the list, to one row, and out of it again. |
| Arrow down and Arrow up | Move focus to the next or previous row. With wrap-focus, focus wraps from the last row to the first, and back. |
| Home and End | Move focus to the first or last row. |
| Page down and Page up | Move focus a page down or up. |
| Enter or Space | Activates the focused row, or picks the focused option. |
One row at a time is in the tab order. The arrow keys move focus between the rows. Rows that only show information are skipped, unless they are interactive.
A row is at least 48px high, and as wide as the list.
ha-list-basehas the rolelist, and its rows the rolelistitem.ha-list-selectablehas the rolelistbox, witharia-multiselectablewhenmultiis set. Its options have the roleoption, andaria-selected.ha-list-navis a navigation landmark, with a list inside.- A disabled option has
aria-disabled="true". A disabled link row setsaria-disabled="true"on its link, and a disabled button row uses a disabled native button. A plainha-list-item-baserow does not tell screen readers that it is disabled.
- Give every list a name with
aria-label, unless a visible heading already names it. - Use
ha-list-item-optiononly inha-list-selectable, andha-list-item-buttonwith anhreffor links.
- Dropdown: a menu of actions
- Select box: picking one option from a few
- Expansion panel: content that people show and hide
The elements are <ha-list-base>, <ha-list-selectable>, and <ha-list-nav>, with <ha-list-item-base>, <ha-list-item-button>, and <ha-list-item-option> rows.
<ha-list-base aria-label="Settings">
<ha-list-item-button
headline="Network"
supporting-text="Connected over Wi-Fi"
>
<ha-svg-icon slot="start" path="..."></ha-svg-icon>
<ha-icon-next slot="end"></ha-icon-next>
</ha-list-item-button>
</ha-list-base><ha-list-selectable multi aria-label="Days">
<ha-list-item-option
appearance="checkbox"
value="monday"
headline="Monday"
></ha-list-item-option>
<ha-list-item-option
appearance="checkbox"
value="tuesday"
headline="Tuesday"
></ha-list-item-option>
</ha-list-selectable>wrap-focus: the arrow keys wrap around at the ends.virtual-focus: focus stays outside the list. The list marks the row the keyboard points at withactive, instead of focusing it.aria-label: the accessible name of the list.
- Default: the rows.
ha-list-activated: Enter or Space on the focused row.detailhas theindexand theitem.
moveActiveItem(): moves the active row tonext,previous,first,last,next-page, orprevious-page. Use it withvirtual-focus.getActiveItemIndex(): the index of the active row.focusItemAtIndex(): focuses the row at an index.
--ha-list-gap: the space between rows. Defaults to0.--ha-list-padding: the padding around the rows. Defaults to0.
multi: people can pick more than one option.controlled: a click only fires the events, and does not changeselected. Set it when the selection comes from your own state.
ha-list-selectable also has the attributes of ha-list-base.
ha-list-item-selected: an option was picked.detailis the index of the option.ha-list-item-deselected: an option was unpicked, withmultionly.detailis the index of the option.
clearSelection(): unpicks every option.
aria-label: the name of the<nav>landmark.
start: an icon, image, or avatar at the start.end: content at the end, like a chevron, a value, or a button.headline: the first line. Overrides theheadlineattribute.supporting-text: the second line. Overrides thesupporting-textattribute.content: replaces the headline and the supporting text.
ha-list-item-button and ha-list-item-option have the same slots.
headline: the first line.supporting-text: the second line.disabled: disables the row.interactive: puts the row in the keyboard navigation of the list, without an action.active: set by a list withvirtual-focuson the row the keyboard points at.
--ha-row-item-min-height: the minimum height of a row. Defaults to48px.--ha-row-item-padding-blockand--ha-row-item-padding-inline: the padding of a row. Default to12pxand16px.--ha-row-item-gap: the space between the start, the text, and the end. Defaults to16px.--ha-list-item-focus-background: the background on keyboard focus.--ha-list-item-active-background: the background of theactiverow.--ha-list-item-focus-radius,--ha-list-item-focus-width,--ha-list-item-focus-width-start, and--ha-list-item-focus-offset: the focus outline.
href: the row renders a link to this URL.target,rel, anddownload: the attributes of the link, withhref.
selected: the option is picked. Set by the list, or by you withcontrolled.indeterminate: the checkbox shows a partly picked state, like for a group.value: a value that identifies the option.appearance:linehighlights the selected row,checkboxshows a checkbox. Defaults toline.selection-position:startorend, where the checkbox goes. Defaults tostart.
--ha-list-item-selected-background: the background of a selected option, inlineappearance.
Source: src/components/list/ha-list-base.ts, src/components/list/ha-list-selectable.ts, src/components/list/ha-list-nav.ts, src/components/item/ha-list-item-base.ts, src/components/item/ha-list-item-button.ts, and src/components/item/ha-list-item-option.ts