Skip to content

Material 3

Get started

Composition

Build interfaces by composing components and slots.

Compose a component from its children: write the icon, the text and the buttons inside it, in place of icon, title or actions props. A child takes its place by its slot, and can be a function of the component's state.

Slots

When a component has several places for its content, set the slot prop on each child to choose its place, as with React Aria's slots.

Ada LovelaceMathematician
Alan TuringComputer scientist
import { Icon, IconButton, List, ListItem } from '@material-web/react'
import { Text } from 'react-aria-components'

export default function Slots() {
  return (
    <List aria-label="Contacts" variant="segmented" className="w-80">
      <ListItem id="ada" textValue="Ada Lovelace">
        <Icon slot="leading" name="person" />
        <Text slot="label">Ada Lovelace</Text>
        <Text slot="description">Mathematician</Text>
        <IconButton slot="trailing" aria-label="Call Ada Lovelace">
          <Icon name="call" />
        </IconButton>
      </ListItem>
      <ListItem id="alan" textValue="Alan Turing">
        <Icon slot="leading" name="person" />
        <Text slot="label">Alan Turing</Text>
        <Text slot="description">Computer scientist</Text>
        <IconButton slot="trailing" aria-label="Call Alan Turing">
          <Icon name="call" />
        </IconButton>
      </ListItem>
    </List>
  )
}

These are the slots of the most used components. A component's page lists its own.

ComponentSlots
AppBarleading, headline, subtitle, search, trailing
ListItemleading, overline, label, description, trailing, selection, drag
MenuItemleading, label, description, trailing
Chipleading, label, and trailing or remove by its variant
Fab, NavigationBarItem, NavigationRailItemlabel
NavigationRailSectionheader
SearchFieldleading, trailing
Dialog, BottomSheettitle, description, close
SideSheettitle, close
SnackbarContenttitle, description
CheckboxGroup, RadioGroupdescription
Calendar, RangeCalendarprevious, next, errorMessage
  • Children: Use Text, Heading, Button and Keyboard from react-aria-components, and Icon, IconButton and Checkbox from @material-web/react, as the children. See Imports.
  • Order: A child is placed by its slot, wherever it is written. Children in the same slot keep the order they are written in.
  • Unknown slots: A child with a slot that the component does not have throws an Invalid slot error, which names the slots it does have.
  • Required slots: Where a component gives a child no place without a slot, the child throws an error too. A Text in a Fab must have slot="label".
  • Plain elements: A plain element, such as an <img> or an avatar, is also placed by its slot attribute, but its slot name is not checked.
  • No slots: A component with a single place for its content takes plain children with no slot, such as the label and icon of a Button or a Tab.

Icons

An icon is a child of Button, IconButton, Fab and SplitButtonLeading, and a child in the leading or trailing slot of a Chip. Any icon works: the Icon component, an icon from an SVG library, or your own component.

// The default: Material Symbols by ligature name
<Button><Icon name="add" />Create</Button>

// An SVG icon library, or your own component, sized to fill the slot
<Button><Plus className="size-5" />Create</Button>

A component sizes the Icon it holds. Give any other icon the same size, such as size-5 for the 20dp icon of a default Button.

Children as a function

Pass a function as children to render content from the component's state, as with React Aria's render props. The function receives the state as one object and returns the children.

import { Icon, IconButton } from '@material-web/react'
import { useState } from 'react'

export default function RenderProps() {
  const [isFavorite, setFavorite] = useState(false)
  return (
    <IconButton aria-label="Favorite" isSelectable isSelected={isFavorite} onChange={setFavorite}>
      {({ isSelected, isHovered }) => (
        <Icon name="favorite" className={isSelected || isHovered ? 'icon-filled' : undefined} />
      )}
    </IconButton>
  )
}
ComponentState
Button, IconButtonisHovered, isPressed, isFocused, isFocusVisible, isDisabled, isPending. A toggle also has isSelected and state.
Fab, FabMenuButton, SplitButtonLeadingisHovered, isPressed, isFocused, isFocusVisible, isDisabled, isPending
SnackbarAction, SnackbarCloseButtonthe same
ListItemisHovered, isPressed, isFocused, isFocusVisible, isFocusVisibleWithin, isSelected, isDisabled, selectionMode, selectionBehavior, allowsDragging, isDragging, isDropTarget, id, state
MenuItem, FabMenuItemisHovered, isPressed, isFocused, isFocusVisible, isSelected, isDisabled, hasSubmenu, isOpen, selectionMode, selectionBehavior, allowsDragging, isDragging, isDropTarget
ChipisHovered, isPressed, isFocused, isFocusVisible, isSelected, isDisabled, allowsRemoving, selectionMode, selectionBehavior
TabisHovered, isPressed, isFocused, isFocusVisible, isSelected, isDisabled
NavigationBarItem, NavigationRailItemisHovered, isPressed, isFocused, isFocusVisible, isSelected, isDisabled, state
CheckboxisSelected, isIndeterminate, isHovered, isPressed, isFocused, isFocusVisible, isDisabled, isReadOnly, isInvalid, isRequired
RadioisSelected, isHovered, isPressed, isFocused, isFocusVisible, isDisabled, isReadOnly, isInvalid, isRequired
SwitchisSelected, isHovered, isPressed, isFocused, isFocusVisible, isDisabled, isReadOnly, isInvalid, isRequired, state
CheckboxGroupisDisabled, isReadOnly, isRequired, isInvalid, state
RadioGroupisDisabled, isReadOnly, isRequired, isInvalid, orientation, state
TextField, its leading and trailingisHovered, isFocusWithin, isFocusVisible, isDisabled, isInvalid
NavigationRailSectionthe same
SearchFieldisEmpty, isDisabled, isInvalid, isReadOnly, isRequired, state
Slider, ButtonGrouporientation, isDisabled, state
Tabs, Toolbar, NavigationBar, NavigationRailorientation
TabPanelisFocused, isFocusVisible, isInert, isEntering, isExiting, state
Dialog, SearchView, DatePickerDialog, TimePickerDialogisEntering, isExiting, state
BottomSheet, SideSheetisEntering, isExiting, state, position, swipeDirection, stackIndex, hasDescendants, isExpanded
MenuPopover, FabMenuPopover, TooltipPopoverisEntering, isExiting, placement, trigger
TooltipisEntering, isExiting, placement, state
Snackbartoast, isFocused, isFocusVisible
LinearProgressIndicator, CircularProgressIndicator, LoadingIndicatorpercentage, valueText, isIndeterminate
Calendar, RangeCalendarisDisabled, isInvalid, state
CalendarCelldate, formattedDate, isSelected, isSelectionStart, isSelectionEnd, isHovered, isPressed, isFocused, isFocusVisible, isDisabled, isUnavailable, isInvalid, isToday, isOutsideMonth, isOutsideVisibleRange
DatePicker, DateRangePickerdisplayMode
TimePickerdisplayMode, selection
  • Focus: isFocused is any focus, and isFocusVisible is keyboard focus only. On a MenuItem or a FabMenuItem, isFocused is also true while the pointer is on the item.
  • Toggles: A Button or an IconButton reports isSelected only when it is a toggle, with isSelectable.
  • Text fields: On a TextField, pass the function as leading or trailing instead of children. isFocusWithin is true while the input has the focus.
  • One child: The function must be the only child. To return several children, use a fragment or an array with keys.
  • Slots: The children a function returns take slots as written children do.
  • Types: The type of the state is exported under the component's name for most components, such as ListItemRenderProps and MenuItemRenderProps.
  • Classes: className and style take a function of the state too. See Styling.

Collections

Write the items of a List, a Menu, a FabMenu, a ChipGroup or a TabList as children, or pass items and a function that renders each one, as with React Aria's collections.

Annual report
Budget
Meeting notes
import { List, ListItem } from '@material-web/react'
import { useState } from 'react'
import type { Selection } from 'react-aria-components'

const files = [
  { id: 'report', name: 'Annual report' },
  { id: 'budget', name: 'Budget' },
  { id: 'notes', name: 'Meeting notes' },
]

export default function Collections() {
  const [selected, setSelected] = useState<Selection>(new Set(['budget']))
  return (
    <List
      aria-label="Files"
      variant="segmented"
      className="w-80"
      items={files}
      selectionMode="multiple"
      selectedKeys={selected}
      onSelectionChange={setSelected}
    >
      {(file) => <ListItem>{file.name}</ListItem>}
    </List>
  )
}
  • Ids: Give each item an id, which selection and actions refer to. With items, an item takes the id of its object unless you set one, as in <ListItem id={file.path}>.
  • Text values: Give an item a textValue when its children are not plain text, so that typing can find it.
  • Actions: Set onAction on a List, a Menu, a FabMenu or a ChipGroup to handle a press on an item. It is called with the item's id, as in onAction={(id) => open(id)}.
  • Selection: Set selectionMode on a List, a Menu or a ChipGroup, and read the selected ids with selectedKeys and onSelectionChange. See React Aria's Selection guide.
  • Other values: With items, a rendered item is reused until its object changes. Pass dependencies with the other values the function reads.

Triggers

To open an overlay from an element, wrap the two in a trigger, with the element first.

import {
  Button,
  Dialog,
  DialogTrigger,
  Icon,
  IconButton,
  Menu,
  MenuItem,
  MenuPopover,
} from '@material-web/react'
import { Heading, MenuTrigger } from 'react-aria-components'

export default function Triggers() {
  return (
    <>
      <MenuTrigger>
        <IconButton aria-label="More options">
          <Icon name="more_vert" />
        </IconButton>
        <MenuPopover>
          <Menu>
            <MenuItem id="rename">Rename</MenuItem>
            <MenuItem id="duplicate">Duplicate</MenuItem>
            <MenuItem id="remove">Remove</MenuItem>
          </Menu>
        </MenuPopover>
      </MenuTrigger>

      <DialogTrigger>
        <Button variant="tonal">Remove</Button>
        <Dialog>
          <Heading
            slot="title"
            className="m-0 px-space-300 pb-space-200 text-headline-sm text-on-surface"
          >
            Remove this file?
          </Heading>
          <div className="flex shrink-0 justify-end gap-space-100 px-space-300 pt-space-200">
            <Button variant="text" slot="close">
              Cancel
            </Button>
            <Button variant="text" slot="close">
              Remove
            </Button>
          </div>
        </Dialog>
      </DialogTrigger>
    </>
  )
}
TriggerImport fromOpens
MenuTriggerreact-aria-componentsA MenuPopover, or a FabMenuPopover from a FabMenuButton
SubmenuTriggerreact-aria-componentsA MenuPopover from a MenuItem
DialogTrigger@material-web/reactA Dialog, a DatePickerDialog, a TimePickerDialog, a SearchView, or a TooltipPopover on a press
SheetTrigger@material-web/reactA modal BottomSheet or SideSheet
TooltipTrigger@material-web/reactA Tooltip
PreviewTrigger@material-web/reactA TooltipPopover on hover or focus
  • Element: The element of a trigger is a Button, an IconButton or any other React Aria button. A TooltipTrigger takes any focusable React Aria component.
  • Open state: A trigger keeps the open state itself. To control it, set isOpen and onOpenChange on the trigger. Set defaultOpen to start with the overlay open.
  • No trigger: To open an overlay from anywhere, control it with isOpen and onOpenChange on the overlay itself.
  • Closing: A button with slot="close" inside a dialog or a sheet closes it.