If you have any project questions, concerns, or contribution ideas, join our #pwa Slack channel. Find out how to create an account by visiting Community Resources

List

The List component maps a collection of data objects into an array of elements. It also manages the selection and focus of those elements.

View Source

Props

Name Required Default Description
classes - {} Class names to use when styling this component
getItemKey - ({ id }) => id -
items check_box - -
render check_box - -
renderItem - 'div' A render prop for the list item elements. A tagname string, such as "div", is also valid.
onSelectionChange - - A callback that fires when the selection state changes.
selectionModel - 'radio' A string corresponding to a selection model.

Selection models

The selectionModel currently accepts the following values:

  • radio (default)
  • checkbox

Example


import { List } from '@magento/peregrine';

const simpleData = new Map()
    .set('s', 'Small')
    .set('m', 'Medium')
    .set('l', 'Large')

<List
    classes={{ root: 'foo' }}
    items={simpleData}
    render={'ul'}
    renderItem={'li'}
/>

const complexData = new Map()
    .set('s', { id: 's', value: 'Small' })
    .set('m', { id: 'm', value: 'Medium' })
    .set('l', { id: 'l', value: 'Large' })

<List
    classes={{ root: 'bar' }}
    items={complexData}
    render={props => (<ul>{props.children}</ul>)}
    renderItem={props => (<li>{props.value}</li>)}
/>