Back to Material Components Web

Chip set

packages/mdc-chips/chip-set/README.md

14.0.07.1 KB
Original Source
<!--docs: title: "Chip set" layout: detail section: components excerpt: "Chip sets represent logical groups of chips." iconId: chip path: /catalog/chips/chipset/ -->

Chip set

Chip sets represent logical groups of chips.

Basic usage

Note: there's work planned to replace the mdc-evolution-* prefix of chips with the standard mdc-chip-* prefix.

HTML structure

Chip sets have two varieties: layout grid chip sets and listbox chip sets.

Note: chip sets use the roving tabindex pattern for keyboard navigation. As a result, only one chip action should be in the tab sequence with tabindex="0". All other chip actions, even other action(s) in the same chip, should have tabindex="-1".

Layout grid chip sets

Layout grid chip sets follow the layout grid interaction pattern. They contain either action chips or input chips.

html
<span class="mdc-evolution-chip-set" role="grid">
  <span class="mdc-evolution-chip-set__chips" role="presentation">
    <!-- Contains either action chips or input chips -->
  </span>
</span>

Listbox chip sets

Listbox chip sets follow the follow the listbox interaction pattern They contain filter chips chips.

html
<span class="mdc-evolution-chip-set" role="listbox" aria-orientation="horizontal" aria-multiselectable="true">
  <span class="mdc-evolution-chip-set__chips" role="presentation">
    <!-- Contains filter chips -->
  </span>
</span>

Listbox chip sets support both multi-selection and single-selection. The aria-multiselectable attribute dictates which behavior is applied.

html
<span class="mdc-evolution-chip-set" role="listbox" aria-orientation="horizontal" aria-multiselectable="false">
  <span class="mdc-evolution-chip-set__chips" role="presentation">
    <!-- Contains filter chips -->
  </span>
</span>

API

CSS classes

CSS ClassDescription
mdc-evolution-chip-setMandatory, for the chip set root.
mdc-evolution-chip-set__chipsMandatory, for the element containing the chips.
mdc-evolution-chip-set--overflowOptional, causes the chips to overflow instead of wrap (their default behavior).

Sass mixins

Access to theme mixins require importing the chips theme style module.

scss
@use "@material/chips";
MixinDescription
horizontal-space-between-chips($space)Sets the horizontal space between chips in the chip set.
vertical-space-between-chips($space)Sets the vertical space between chips in the chip set.

MDCChipSet methods

Method SignatureDescription
getChipIndexByID(chipID: string): numberReturns the index of the chip with the given id.
getChipIdAtIndex(index: number): stringReturns the id of the chip at the given index.
getSelectedChipIndexes(): ReadonlySet<number>Returns the indexes of the selcted chips (if any). Only supported for listbox chip sets.
setChipSelected(index: number, action: MDCChipActionType, isSelected: boolean): voidSets the chip to be selected at the given index. Only supported for listbox chip sets.
isChipSelected(index: number, action: MDCChipActionType): booleanReturns the selected state of the chip at the given index. Only supported for listbox chip sets.
removeChip(index: number): booleanReturns the selected state of the chip at the given index. Only supported for listbox chip sets.

MDCChipSetEvents

Event nameDetailDescription
MDCChipSet:interactionMDCChipSetInteractionEventDetailEmitted when a chip is interacted with.
MDCChipSet:removalMDCChipSetRemovalEventDetailEmitted when a chip is removed. Check the detail to know when the removal animation is complete.
MDCChipSet:selectionMDCChipSetSelectionEventDetailEmitted when a chip selected state changes.

MDCChipSetAdapter

Method SignatureDescription
announceMessage(message: string): voidAnnounces the message to screen readers via an aria-live region.
emitEvent<D extends object>(eventName: MDCChipSetEvents, eventDetail: D): voidEmits the given eventName with the given eventDetail.
getAttribute(attrName: MDCChipSetAttributes): string|nullReturns the value for the given if attribute or null if it does not exist.
getChipActionsAtIndex(index: number): MDCChipActionType[]Returns the actions provided by the child chip at the given index.
getChipCount(): numberReturns the number of child chips.
getChipIdAtIndex(index: number): stringReturns the ID of the chip at the given index.
getChipIndexById(chipID: string): numberReturns the index of the child chip with the matching ID.
isChipFocusableAtIndex(index: number, actionType: MDCChipActionType): booleanProxies to the MDCChip#isActionFocusable method.
isChipSelectableAtIndex(index: number, actionType: MDCChipActionType): booleanProxies to the MDCChip#isActionSelectable method.
isChipSelectedAtIndex(index: number, actionType: MDCChipActionType): booleanProxies to the MDCChip#isActionSelected method.
removeChipAtIndex(index: number): voidRemoves the chip at the given index.
setChipFocusAtIndex(index: number, action: MDCChipActionType, focus: FocusBehavior): voidProxies to the MDCChip#setActionFocus method.
setChipSelectedAtIndex(index: number, actionType: MDCChipActionType, isSelected: boolean): voidProxies to the MDCChip#setActionSelected method.
startChipAnimationAtIndex(index: number, animation: Animation): voidStarts the chip animation at the given index.

MDCChipSetFoundation

Method SignatureDescription
handleChipAnimation(event: ChipAnimationEvent): voidHandles the chip animation event.
handleChipInteraction(event: ChipInteractionEvent): voidHandles the chip interaction event.
handleChipNavigation(event: ChipNavigationEvent): voidHandles the chip navigation event.
getSelectedChipIndexes(): ReadonlySet<number>Returns the unique selected indexes of the chips (if any).
setChipSelected(index: number, action: MDCChipActionType, isSelected: boolean): voidSets the selected state of the chip at the given index and action.
isChipSelected(index: number, action: MDCChipActionType): booleanReturns the selected state of the chip at the given index and action.
removeChip(index: number): voidRemoves the chip at the given index.
addChip(index: number): voidAnimates the addition of the chip at the given index.

Usage within frameworks

If you are using a JavaScript framework, such as React or Angular, you can create a chip set for your framework. Depending on your needs, you can use the Simple Approach: Wrapping MDC Web Vanilla Components, or the Advanced Approach: Using Foundations and Adapters. Please follow the instructions here.