Package detail

@material/react-list

material-components5.5kMIT0.15.0

Material Components React List

mdc web react, material components react, material design, list

readme

React List

A React version of an MDC List.

Installation

npm install @material/react-list

Usage

Styles

with Sass:

import '@material/react-list/index.scss';

with CSS:

import '@material/react-list/dist/list.css';

Javascript Instantiation

import React, {Component} from 'react';
import List, {ListItem, ListItemText} from '@material/react-list';

class MyApp extends Component {
  render() {
    return (
      <List>
        <ListItem>
          <ListItemText primaryText='Photos'/>
        </ListItem>
        <ListItem>
          <ListItemText primaryText='Recipes'/>
        </ListItem>
        <ListItem>
          <ListItemText primaryText='Work'/>
        </ListItem>
      </List>
    );
  }
}

NOTE: Please use the ListItem component to specify list items. List will not recognize custom list item components.

Also, you can override the element that the List or ListItem renders by passing in a tag prop. By default, List renders a ul and ListItem renders an li. For semantic HTML and a11y, as well as working with routing libraries such as React Router and Next.js' Link, you may wish to use nav and a respectively if using the components to render a page's navigation.

Variants

Two-Line List

You can use the twoLine Boolean prop for List combined with the secondaryText prop for ListItem to style a list as a double line list.

import React, {Component} from 'react';
import List, {ListItem, ListItemText} from '@material/react-list';

class MyApp extends Component {
  render() {
    return (
      <List twoLine>
        <ListItem>
          <ListItemText
            primaryText='Photos'
            secondaryText='Jan 9, 2018' />
        </ListItem>
        <ListItem>
          <ListItemText
            primaryText='Recipes'
            secondaryText='Jan 17, 2018' />
        </ListItem>
        <ListItem>
          <ListItemText
            primaryText='Work'
            secondaryText='Jan 28, 2018' />
        </ListItem>
      </List>
    );
  }
}

List item supporting visuals and metadata

You may add a leading visuals or trailing metadata to a list item using ListItemGraphic before or ListItemMeta after ListItemText.

import React, {Component} from 'react';
import MaterialIcon from '@material/react-material-icon';
import List, {ListItem, ListItemGraphic, ListItemText, ListItemMeta} from '@material/react-list';

class MyApp extends Component {
  render() {
    return (
      <List>
        <ListItem>
          <ListItemGraphic graphic={<MaterialIcon icon='folder'/>} />
          <ListItemText primaryText='Photos' />
          <ListItemMeta meta='info' />
        </ListItem>
        ...
      </List>
    );
  }
}

List groups and list dividers

Multiple related lists can be grouped together using the ListGroup component. Optional subheaders can be added using ListGroupSubheader. ListDividers can be used to separate content either within a list or between lists.

import React, {Component} from 'react';
import List, {
  ListItem, ListItemText, ListGroup,
  ListGroupSubheader,ListDivider
} from '@material/react-list';

class MyApp extends Component {
  render() {
    return (
      <ListGroup>
        <ListGroupSubheader tag='h2'>Folders</ListGroupSubheader>
        <List>
          <ListItem>
            <ListItemText primaryText='Photos' />
          </ListItem>
          ...
        </List>
        <ListDivider tag="div" />
        <ListGroupSubheader tag='h2'>Recent Files</ListGroupSubheader>
        <List>
          <ListItem>
            <ListItemText primaryText='Vacation' />
          </ListItem>
          ...
        </List>
      </ListGroup>
    );
  }
}

Single Selection

You can use the singleSelection Boolean prop for List to allow for selection of list items. You can also set the selectedIndex of the list programmatically and include a handleSelect callback.

NOTE: If you are inserting or removing list items, you must update the selectedIndex accordingly.

import React, {Component} from 'react';
import List, {ListItem, ListItemText} from '@material/react-list';

class MyApp extends Component {
  state = {
    selectedIndex: 1,
  };

  render() {
    return (
      <List
        singleSelection
        selectedIndex={this.state.selectedIndex}
        handleSelect={(selectedIndex) => this.setState({selectedIndex})}
      >
        <ListItem>
          <ListItemText primaryText='Photos'/>
        </ListItem>
        <ListItem>
          <ListItemText primaryText='Recipes'/>
        </ListItem>
        <ListItem>
          <ListItemText primaryText='Work'/>
        </ListItem>
      </List>
    );
  }
}

Checkbox Lists

You can use the checkboxList Boolean prop for List to enable the checkbox list logic. You must also set selectedIndex of the list to an array. selectedIndex will be an empty array if there is no initial selection. Setting selectedIndex will initialize the list with the correct tabIndex. Changing this programatically will not affect the checkboxes -- you must programatically change the checkbox via it's checked prop and update selectedIndex to keep a11y up to date. See the Checkbox Readme for more details.

import React, {Component} from 'react';
import List, {ListItem, ListItemText} from '@material/react-list';
import Checkbox from '@material/react-checkbox';

class MyApp extends Component {
  state = {
    selectedIndex: [1],
  };

  render() {
    return (
      <List
        checkboxList
        selectedIndex={this.state.selectedIndex}
        handleSelect={(activatedIndex, allSelected) => this.setState({selectedIndex: allSelected})}
      >
        <ListItem>
          <Checkbox />
          <ListItemText primaryText='Photos'/>
        </ListItem>
        <ListItem>
          <Checkbox checked />
          <ListItemText primaryText='Recipes'/>
        </ListItem>
        <ListItem>
          <Checkbox />
          <ListItemText primaryText='Work'/>
        </ListItem>
      </List>
    );
  }
}

Radio Lists

You can use the radioList Boolean prop for List to enable the radio list logic. Set selectedIndex to the index of the listItem initially selected to accurately setup the component for a11y. Changing selectedIndex programatically will not affect the radio element -- you must instead programatically change the radio via it's checked prop. Interactions (click/arrow keys) will update the radios as expected. To get the selectedIndex, setup the radio's onChange method as shown below. See the Radio Readme for more details.

Note: We know this API is inconsistent with checkbox list. This is because the implementations of radio and checkbox differ. In the coming months, we will try to normalize the design.

import React, {Component} from 'react';
import List, {ListItem, ListItemText} from '@material/react-list';
import Radio, {NativeRadioControl} from '@material/react-radio';

class MyApp extends Component {
  state = {
    selectedItem: 'Milk',
  };

  handleChange = (e) => {
    this.setState({selectedItem: e.target.value});
  }

  render() {
    const listItems = ['Photos', 'Recipes', 'Work'];

    return (
      <List
        radioList
        selectedIndex={0}
      >
        {
          listItems.map((item, index) => {
            return (
              <ListItem key={index}>
                <Radio>
                  <NativeRadioControl
                    name={item}
                    checked={this.state.selectedItem === item}
                    value={item}
                    id={`${index}-${item}`}
                    onChange={this.handleChange}
                  />
                </Radio>
                <ListItemText primaryText='Photos'/>
              </ListItem>
            );
          })
        }
      </List>
    );
  }
}

Props

List

Prop Name Type Description
className String Classes to be applied to the list element
nonInteractive Boolean Disables interactivity affordances
dense Boolean Styles the density of the list, making it appear more compact
avatarList Boolean Configures the leading tiles of each row to display images instead of icons. This will make the graphics of the list items larger
twoLine Boolean Styles the list with two lines
singleSelection Boolean Allows for single selection of list items
wrapFocus Boolean Sets the list to allow the up arrow on the first element to focus the last element of the list and vice versa
checkboxList Boolean Set the list to act as a checkbox list
radioList Boolean Set the list to act as a radio list
selectedIndex Number Array<Number> Toggles the selected state of the list item at the given index. Behaves differently for checkboxList and radioList (see sections above for more detail).
handleSelect Function(activatedItemIndex: Number, selected: Number Array<Number>) => void Callback for handling a list item selection event. selected will be an Array,Number> for checkbox lists.
orientation 'vertical' \ 'horizontal' Indicates the list orientation (defaults to 'vertical').
tag String Customizes the list tag type (defaults to 'ul')

ListItem

Prop Name Type Description
tag String Customizes the list tag type (defaults to 'li')
checkboxList Boolean Set the list item to act as a checkbox list
radioList Boolean Set the list item to act as a radio list
activated Boolean Sets the list item to the activated state
selected Boolean Sets the list item to the selected state

ListItemText

Prop Name Type Description
className String Classes to be applied to the list item text element
tabIndex Number Tab index of the list item text
primaryText String Primary text for the list item
secondaryText String Secondary text for the list item

ListItemGraphic

Prop Name Type Description
className String Classes to be applied to the list item graphic element
tabIndex Number Tab index of the list item graphic
graphic Element The graphic element to be displayed in front of list item text

ListItemMeta

Prop Name Type Description
className String Classes to be applied to the list item meta element
tabIndex Number Tab index of the list item meta
meta Element or String The meta element or string to be displayed behind list item text

ListDivider

Prop Name Type Description
className String Classes to be applied to the list divider
tag String Element tag of the list divider, defaults to li
role String ARIA role of the list divider, defaults to separator

ListGroup

Prop Name Type Description
className String Classes to be applied to the list group
tag String Element tag of the list group, defaults to div

ListGroupSubheader

Prop Name Type Description
className String Classes to be applied to the list group subheader
tag String Element tag of the list group subheader, defaults to h3

Sass Mixins

Sass mixins may be available to customize various aspects of the Components. Please refer to the MDC Web repository for more information on what mixins are available, and how to use them.

Advanced Sass Mixins

changelog

0.15.0 (2019-07-22)

Bug Fixes

  • infrastructure: chips need unique key (#974) (58408c8)
  • infrastructure: add eslint ignore lines (#973) (7172019)
  • list: Only apply aria-orientation with role (#945) (beab319)
  • list: Remove selected & activated from prop spread (#977) (4f36078)
  • ripple: broken relative imports (#953) (aabe0c1)

Features

  • list: Implement getAttributeForElementIndex (#948) (00f2ef1)

BREAKING CHANGES

  • list: 'orientation` is now used instead of 'aria-orientation' to specify list orientation. This allows smarter aria defaults that can be overridden if needed.

0.14.1 (2019-07-02)

Bug Fixes

  • infrastructure: fix SSR support for webpack4 update (#956) (5d3a89d)

0.14.0 (2019-06-25)

Bug Fixes

  • master on travis.yml (#922) (407de75)
  • infrastructure: update docker command to run new image (#923) (10a68f6)
  • npm vulnerabilities (#903) (92a1840)
  • switch react to peerDependency for all packages (#940) (cc06add)
  • ripple: focus style alive when disabled (#943) (e222e94)
  • ripple: not activating when clicked after touch (#932) (b2f7855)
  • text-field: label isn't float when set value with setState (#934) (f829e12)

chore

Features

  • infrastructure: add typescript production typings test (#900) (1f7f872)
  • select: add 'form' attribute to NativeControl component (#907) (044117f)
  • tab: Allow to render Tab as an anchor node (#928) (5108e76)
  • text-field: add placeholder property (#930) (0818061)

BREAKING CHANGES

  • text-field: handleValueChange is removed from Input's props.
  • top-app-bar: Top App Bar render props removed

0.13.2 (2019-06-11)

Bug Fixes

  • list: update checkbox and radio deps (#919) (685b23b)

0.13.0 (2019-05-30)

Bug Fixes

  • chips: ClientRect/DOMRect is not IE11 compatible (#855) (88697da)
  • chips: error with undefined or null children (#883) (d733c29)
  • chips, text-field: add null check for foundation (#675) (#870) (40ca635)
  • select: className option is passed to select and overrides selectClassName (#872) (6e2aac1)
  • select: componentDidUpdate handles disabled prop change (#877) (db7f0ce)
  • select: edit * imports (#874) (33eb962)

Features

0.12.1 (2019-05-08)

Bug Fixes

  • fab: Made initRipple and unbounded props optional (#854) (baca67b)
  • infrastructure: fix postinstall (#842) (5077078)

Features

  • button: define CSS_CLASSES (#838) (cbf6cc5)
  • text-field: Sync inputComponent when component is updated (#848) (2b954fa )

0.12.0 (2019-05-01)

Bug Fixes

  • list make listitem props optional (#766) (ffd7776)
  • top-app-bar change scrollTop to offsetTop in getViewportScrollY ( (#832) (a207b0d)
  • Ensure all package.json files have a link to the repo (#807) (10f2614)
  • Remove MDCTextfield Constant External (#803) (2269920)

Features

BREAKING CHANGES

  • Text-field, select, list have API changes. Please see PR #830 for more details.

0.11.0 (2019-03-19)

Bug Fixes

  • chips: update classnames version to 2.2.6 (#702) (bfd2986)
  • dialog: should extend HTMLElement (#723) (af449f4)
  • infrastructure: remove duplicate tsconfig properties (#736) (582cca3)
  • menu-surface: Hoist menu-surface via a portal (#500,#628) (#693) (41d8750)
  • ripple: ClientRect => defaultrect object (#754) (b2f78e8)
  • ripple: Use mdc-dom.matches instead of getMatchesProperty() (#706) (74d07fd)
  • select: pass state.value to NativeControl as prop.value (#726) (09ad132)
  • classnames@2.2.5 --> classnames@2.2.6 & update imports (#709) (230337e)
  • make require props optional (#737) (f4e78e7)
  • select: prop value should be string only (#725) (619d12c)
  • snackbar: Add missing mdcw snackbar dependency (#714) (9e6fc92)
  • tab: Set initial tabIndex state to -1 (#690) (#691) (9034c98)
  • text-field: make props optional (#735) (93e8c15)

Features

0.10.0 (2019-02-19)

Bug Fixes

  • button: Support anchor and button HTML attributes (#679) (#680) (be8790e)
  • checkbox: enable name attribute (#678) (2c77ab5)
  • chips: ChipSet no longer overwrites handle[Interaction|Select|Re… (#651) (e0b0946)
  • chips: copy selectedChipIds before calling setState (#645) (37905d3)
  • chips: id shuold be required prop (#649) (afc16c8)
  • infrastructure: fix source mappings under dist directory (#682) (9f93ef3)
  • infrastructure: Upgrade resemblejs to v3 (#634) (53abeac)
  • infrastructure: Windows development (#662) (fbc4b26)
  • list: renders a list with children which is not DOM (#674) (e66a267)
  • ripple: Ripple triggers twice on mobile (#646) (6876e62)
  • tab: return ScrollContentWidth (#633) (c4a2a01)
  • text-field: Do not import constants from @material/textfield internals (#639) (3b3a0ab)
  • top-app-bar: clientHeight unit test (#668) (9c7330b)

Features

  • chips: implements missing adapter method notifyTrailingIconInteraction (#653) (c5e87a6)
  • fab: exited (#661) (a646a33)
  • infrastructure: Fix screenshot tests for external contributors and pull requests (#638) (3d421b1)
  • snackbar: new component (#620) (63e1fce)

BREAKING CHANGES

  • chips: renamed chip.props.removeIcon --> chips.props.trailingIcon

0.9.3 (2019-02-14)

Bug Fixes

0.9.2 (2019-01-30)

0.9.1 (2019-01-30)

0.9.0 (2019-01-23)

Bug Fixes

  • list: Support null as a child element for ListItem (#584) (bf487d7)
  • ripple: add missing dependency to package.json (#612) (f6e4725)
  • ripple: Adds HTMLElement shim to fix regression for SSR projects (#592) (3aaf871)
  • text field: adds missing adapter method notifyIconAction on Icon (#600) (632896a)
  • top-app-bar: make top app bar props optional (#587) (1585c95)

Features

0.8.0 (2018-12-28)

Bug Fixes

  • infrastructure: add declaration package.json (#572) (8cb4b1b)
  • infrastructure: condense webpack configuration build step into one json file (#571) (512f3aa)
  • infrastructure: unit test code coverage for typescript (#487) (1170a1f)
  • list: minification-safe element type comparison (#509) (89f5fd2)
  • select: defensive foundation check before unmounting - also includes radio, checkbox, text-field (#512) (2ee4c80)
  • top-app-bar: foundation should be destroyed and reinitialized on variant change (#519) (58cfc6f)
  • lint for typings files (#577) (8f971a8)
  • remove prop-types from package.json (#576) (7f38952)

Features

BREAKING CHANGES

  • infrastructure: Remove <package-name>.es.js files. The alternate is now to use the index.tsx files.
  • ripple: withRipple is no longer the default export.

0.7.1 (2018-11-30)

Bug Fixes

  • added missing comma from golden.json (#426) (dfe44dc)
  • chips: update to v0.41.0 (#424) (e40fec6)
  • drawer: initialize foundation if props.open updates (#427) (36e6316)
  • drawer: replace focus trap with vanilla version (#437) (bd7433b)
  • drawer: update modal screenshot golden (#482) (ce0c314)
  • linear-progress: Add linear progress (#450) (f38d575)
  • select: added check for nativeControl element before calling props.setRippleCenter in NativeControl (#478) (5baad76)
  • tab-bar: set previousActiveIndex to props.activeIndex initially to avoid tab of undefined error (#428) (8e28944)
  • text-field: custom validation (#430) (f5c9c35)
  • text-field: uncomment test fixed from 0.35.0 (#404) (3a908ff)

Features

0.6.2 (2018-11-07)

Bug Fixes

  • checkbox: add focusable=false to svg for a11y (#375) (c7f3b97)
  • drawer: update readme and screenshots to support below top app bar (#397) (90adbbe)
  • infrastructure: increase screenshot timeout to decrease flakes (#373) (e96ca10)
  • layout-grid: remove unit test console warnings (#379) (408cdd2)
  • list: selectedIndex 0 isn't working (#387) (4e62aae)
  • text-field: added reference to input element (#414) (ea04dc6)
  • text-field: allow for input isValid override (#374) (7872856)
  • text-field: put foundation on state and do render input unless foundation is present (#353) (2cb5d64)
  • text-field: remove foundation.setValue call during onChange (#350) (36469f7)
  • top-app-bar: add FixedAdjust to npmignore (#371) (d4ad675)
  • top-app-bar: allow react elements in title (#376) (f6da361)

Code Refactoring

Features

  • infrastructure: add verify pkg main to dist script (#320) (459c6dd)

BREAKING CHANGES

  • list: Event handlers moved from list to list item. New props on list item for focus, follow href, toggle checkbox, and classnames/attributes passed down from list. Remove ID prop from list item.

0.6.0 (2018-10-24)

Bug Fixes

  • chips: added npmignore (#317) (ac99ac5)
  • chips: replace relative path with npm package (#297) (93ac25e)
  • icon-button: add main field to package.json (#300) (88d5e4e)
  • icon-button: add MIT license to files (#313) (97ecb3a)
  • icon-button: update main property (#319) (e79995d)
  • infrastructure: add more time to screenshot initial wait (#314) (375206e)
  • infrastructure: fix travis badge on readme (#331) (e637782)
  • infrastructure: speed up prerelease script (#288) (b77819f)
  • menu-surface: fix menu surface unit test typo (#315) (8b60622)
  • text-field: Add support for <textarea> (#118) (#266) (d9cff89)
  • text-field: floating label width calculation when notched (#347) (377f250)
  • top-app-bar: add fixed adjust component (#349) (f1d4be0)

Features

0.5.1 (2018-09-25)

Bug Fixes

  • line-ripple: stop calling foundation.setRippleCenter when argument is NaN (#287) (4bbc4fa)

0.5.0 (2018-09-25)

Bug Fixes

  • card: add missing hasRipple (#248) (#255) (d2f58d6)
  • chips: add chip leading icon class management (#281) (c638e79)
  • chips: remove handleRemove method for chipsUpdate method (#282) (8435079)
  • chips: use notifyRemoval and notifyInteraction adapter methods (#277) (ba433ea)
  • infrastructure: add the es5 @material/package/dist/mdc.package to externals (#223) (73fb45b)
  • ripple: react-ripple does not contain styles (#172) (#251) (ac0f87f)
  • tab: update readme and ref name in tab component (#226) (f18fda1)
  • tab-bar: add missing url from screenshot list (#264) (dd2f183)
  • tab-bar: Arrow keys should focus adjacent tab (#280) (54224c8)
  • tab-indicator: update component to work with mdc tab (#215) (bc41a8b)
  • tab indicator sliding animation broken (#273) (c436f58)

Features

BREAKING CHANGES

  • chips: Updated API for selectedChipIds and handleSelect props in ChipSet and id prop in Chip.

0.4.2 (2018-08-14)

0.4.1 (2018-08-13)

Bug Fixes

  • infrastructure: point all tests to es6 files for accurate test coverage (#198) (4959266)
  • ripple: add test to avoid computeBoundingRect error (#200) (769b15b)
  • screenshot increase timeout (#210) (e9a2089)
  • text-field: add missing prop style (#184) (ff9704d)
  • text-field: fix typo in readme (#197) (f88f180)
  • text-field: update isRtl to a prop (#195) (cd7c7c8)

Features

BREAKING CHANGES

  • text-field: In order for rtl to work on the Notched Outline component, isRtl will need to be passed in as boolean (default is false). Updating isRtl will result in a re-render.

0.4.0 (2018-07-30)

Bug Fixes

  • infrastructure: updated deploy steps to run with docker (#116) (a53fc7d)
  • downgraded to es2015 preset to work on ie11 (#133) (05c0184)
  • material-icon: removed blocking line and updated documentation (#155) (8f3cef5)
  • ripple: setState warning when unmounting the component (#112) (841a1c8)
  • text-field: move handleValueChange call when this.props.value updates (#170) (f46a34d)
  • top-app-bar: add material icon imports in screenshot tests (#168) (526400b)
  • point packages to MDC Web /dist ES5 files (#182) (9d387d3)

Chores

  • fab: Pass icon as a prop, not a child element (#159) (1569f97)

Features

  • button: Add an href prop to use anchor tag instead of button (#174) (0df9967)
  • chips: Add new component (#117) (410da30)
  • chips: Add selection to chips (#121) (3ef1123)
  • ripple: Call focus/blur handlers from foundation (#135) (c438333)

BREAKING CHANGES

  • fab: Please update your FAB to pass icon as a prop, not as a child element.
  • chips: Users should render Chip components directly instead of passing a labels prop to ChipSet.

0.3.0 (2018-06-25)

Bug Fixes

  • Moved importer code to webpack.util to share between screen shot test and main build. (aec8cc8)
  • travis and docker integration (#92) (e7f4497)
  • updated function name and tests (7c2794d)
  • line-ripple: Convert style name to camel case (#99) (2a5341c)
  • text-field: Added SASS importer to lookup the package folder first then fallback to default npm resolve. (bf7f849)
  • text-field: Added text-field to valid commit msg list (3922e2c)
  • text-field: Updated Input.js to use new public API of foundation (df0b5ed)

Features

  • Docker integration into Travis to decrease false negative screenshots (#91) (d8b670e)
  • updated all packages to 0.36.0 (#104) (a1d8b66)
  • infrastructure: add .npmignores to packages (#110) (ab7009d)
  • infrastructure: default npm entry point to ES5 (#108) (1f0446f)

0.2.0 (2018-06-01)

Bug Fixes

  • Remove scss extensions from @material/mdc-* imports (#62) (46b7f08)
  • button: Rename stroked to outlined (#74) (f612388)
  • infrastructure: fixed npm run build error for empty package directories (#85) (18666d4)
  • infrastructure: Make all components public (#43) (27a1ab1)
  • ripple: Trigger on key events (2248f26)

Features

0.1.0 (2018-05-09)

Bug Fixes

  • button: Update package.json (507298e)
  • card: Update package.json (fc7a4dd)
  • fab: Update package.json (efd4703)
  • floating-label: Update package.json (92cbf2c)
  • line-ripple: Update package.json (b6fc89c)
  • material-icon: Update package.json (18e2508)
  • notched-outline: Update package.json (8b18779)
  • ripple: Update package.json (044c308)
  • text-field: Update package.json (fda82fb)
  • top-app-bar: Update package.json (06e9d66)

Features

  • remote hosted screenshot testing (#12) (98bcdfe)
  • screenshot testing (#10) (5fd6d86)
  • fab: Add new tests for svg/img (1f536b7)
  • fab: Change node to element. (2b4960e)
  • fab: Remove empty fab from test. Add waitUntil idle to wait until the stylesheets finish (43e58d4)
  • fab: Update class name (96c2d61)
  • fab: Update for comments (9b041d6)
  • fab: Update for comments (676ae32)
  • fab: Update for lint (3748f31)
  • fab: Update package name (02b7140)