Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@material/chips

Package Overview
Dependencies
Maintainers
11
Versions
1672
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material/chips

The Material Components for the Web chips component

  • 0.32.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
594K
decreased by-15.31%
Maintainers
11
Weekly downloads
 
Created
Source

Chips

Chips are compact elements that allow users to enter information, select a choice, filter content, or trigger an action.

Design & API Documentation

  • Material Design guidelines: Chips
  • Demo

Installation

npm install --save @material/chips

Usage

HTML Structure

<div class="mdc-chip-set">
  <div class="mdc-chip" tabindex="0">
    <div class="mdc-chip__text">Chip content</div>
  </div>
  <div class="mdc-chip" tabindex="0">
    <div class="mdc-chip__text">Chip content</div>
  </div>
  <div class="mdc-chip" tabindex="0">
    <div class="mdc-chip__text">Chip content</div>
  </div>
</div>
Leading and Trailing Icons

You can optionally add a leading icon (i.e. thumbnail) and/or a trailing icon to a chip. To add an icon, add an i element with your preferred icon, give it a class of mdc-chip__icon, and a class of either mdc-chip__icon--leading or mdc-chip__icon--trailing. If you're adding a trailing icon, also set tabindex="0" and role="button" to make it accessible by keyboard and screenreader.

Leading icon
<div class="mdc-chip">
  <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">event</i>
  <div class="mdc-chip__text">Add to calendar</div>
</div>
Trailing icon
<div class="mdc-chip">
  <div class="mdc-chip__text">Jane Smith</div>
  <i class="material-icons mdc-chip__icon mdc-chip__icon--trailing" tabindex="0" role="button">cancel</i>
</div>

CSS Classes

CSS ClassDescription
mdc-chip-setMandatory. Indicates the set that the chip belongs to
mdc-chip-set--choiceOptional. Indicates that the chips in the set are choice chips, which allow a single selection from a set of options.
mdc-chip-set--filterOptional. Indicates that the chips in the set are filter chips, which allow multiple selection from a set of options.
mdc-chipMandatory.
mdc-chip__textMandatory. Indicates the text content of the chip
mdc-chip__iconOptional. Indicates an icon in the chip
mdc-chip__icon--leadingOptional. Indicates a leading icon in the chip
mdc-chip__icon--trailingOptional. Indicates a trailing icon in the chip

NOTE: Every element that has an mdc-chip__icon class must also have either the mdc-chip__icon--leading or mdc-chip__icon--trailing class.

Sass Mixins

To customize the colors of any part of the chip, use the following mixins.

MixinDescription
mdc-chip-set-spacing($gap-size)Customizes the amount of space between each chip in the set
mdc-chip-corner-radius($radius)Customizes the corner radius for a chip
mdc-chip-fill-color-accessible($color)Customizes the background fill color for a chip, and updates the chip's ink and ripple color to meet accessibility standards
mdc-chip-fill-color($color)Customizes the background fill color for a chip
mdc-chip-ink-color($color)Customizes the text ink color for a chip, and updates the chip's ripple color to match
mdc-chip-selected-ink-color($color)Customizes text ink and ripple color of a chip in the selected state
mdc-chip-stroke($width, $style, $color)Customizes the border stroke properties for a chip
mdc-chip-stroke-width($width)Customizes the border stroke width for a chip
mdc-chip-stroke-style($style)Customizes the border stroke style for a chip
mdc-chip-stroke-color($color)Customizes the border stroke color for a chip

NOTE: mdc-chip-set-spacing also sets the amount of space between a chip and the edge of the set it's contained in.

MDCChip and MDCChipSet

The MDC Chips module is comprised of two JavaScript classes:

  • MDCChip defines the behavior of a single chip
  • MDCChipSet defines the behavior of chips within a specific set. For example, chips in an entry chip set behave differently from those in a filter chip set.

To use the MDCChip and MDCChipSet classes, import both classes from @material/chips.

MDCChip
Method SignatureDescription
toggleSelected() => voidProxies to the foundation's toggleSelected method
PropertyValue TypeDescription
rippleMDCRippleThe MDCRipple instance for the root element that MDCChip initializes
MDCChipSet
PropertyValue TypeDescription
chipsArray<MDCChip>An array of the MDCChip objects that represent chips in the set

Adapters: MDCChipAdapter and MDCChipSetAdapter

MDCChipAdapter
Method SignatureDescription
addClass(className: string) => voidAdds a class to the root element
removeClass(className: string) => voidRemoves a class from the root element
hasClass(className: string) => booleanReturns true if the root element contains the given class
registerInteractionHandler(evtType: string, handler: EventListener) => voidRegisters an event listener on the root element
deregisterInteractionHandler(evtType: string, handler: EventListener) => voidDeregisters an event listener on the root element
registerTrailingIconInteractionHandler(evtType: string, handler: EventListener) => voidRegisters an event listener on the trailing icon element
deregisterTrailingIconInteractionHandler(evtType: string, handler: EventListener) => voidDeregisters an event listener on the trailing icon element
notifyInteraction() => voidEmits a custom event MDCChip:interaction denoting the chip has been interacted with, which bubbles to the parent mdc-chip-set element
notifyTrailingIconInteraction() => voidEmits a custom event MDCChip:trailingIconInteraction denoting the chip's trailing icon has been interacted with, which bubbles to the parent mdc-chip-set element
MDCChipSetAdapter
Method SignatureDescription
hasClass(className: string) => booleanReturns whether the chip set element has the given class
registerInteractionHandler(evtType, handler) => voidRegisters an event handler on the root element for a given event
deregisterInteractionHandler(evtType, handler) => voidDeregisters an event handler on the root element for a given event

Foundations: MDCChipFoundation and MDCChipSetFoundation

MDCChipFoundation
Method SignatureDescription
toggleSelected() => voidToggles the selected class on the chip element
MDCChipSetFoundation

None yet, coming soon.

Keywords

FAQs

Package last updated on 05 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc