Skip to main content

What are you looking for?

Try searching for…

Components

Chip

Chip are small, interactive components that allow users to control how they want to see content. For example, they can be used to filter categories in a search result and show which filters are active.

Press Enter to start editing
Unable to parse html
const PreviewEn = () => {
  return (
    <>
      <Chip.Radio name='my-radio' value='english' defaultChecked>
        English
      </Chip.Radio>
      <Chip.Radio name='my-radio' value='norwegian'>
        Norwegian
      </Chip.Radio>
    </>
  );
};

render(<PreviewEn />)

Usage

Chip uses two different HTML structures, but both have the class name ds-chip.

As radio or checkbox

Notice that we put <input> inside <label>, this means you don't need to connect them with for and id.

As removable or button

A removable chip uses a <button> element, but data-removable="true" has been added to indicate that it is a removable chip. Then a cross will appear to the right of the chip, this is drawn with CSS.

With text wrapping

Chips by default force text on a single line, and truncate text with an ellipsis if it overflows. Use data-wrap="wrap" to allow multi-line text inside the chip.

CSS variables and data attributes

Chip also uses ds-input internally when it is a radio or checkbox.

Sizes are controlled with data-size and colors with data-color. The component will inherit from the closest parent where these are set.

CSS Variables
NameValue
--dsc-chip-background--activevar(--ds-color-surface-active)
--dsc-chip-background--checked--activevar(--ds-color-base-active)
--dsc-chip-background--checked--hovervar(--ds-color-base-hover)
--dsc-chip-background--checkedvar(--ds-color-base-default)
--dsc-chip-background--hovervar(--ds-color-surface-hover)
--dsc-chip-backgroundvar(--ds-color-surface-tinted)
--dsc-chip-border-color--checkedtransparent
--dsc-chip-border-colorvar(--ds-color-border-subtle)
--dsc-chip-border-radius--checkbox-inputvar(--ds-border-radius-sm)
--dsc-chip-border-radius--checkboxvar(--ds-border-radius-md)
--dsc-chip-border-radiuscalc(var(--dsc-chip-height)/2)
--dsc-chip-border-stylesolid
--dsc-chip-border-widthvar(--ds-border-width-default)
--dsc-chip-colorvar(--ds-color-text-default)
--dsc-chip-heightvar(--ds-size-8)
--dsc-chip-icon-sizevar(--ds-icon-size)
--dsc-chip-icon-urlurl("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' fill='none' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' d='M6.53 5.47a.75.75 0 0 0-1.06 1.06L10.94 12l-5.47 5.47a.75.75 0 1 0 1.06 1.06L12 13.06l5.47 5.47a.75.75 0 1 0 1.06-1.06L13.06 12l5.47-5.47a.75.75 0 0 0-1.06-1.06L12 10.94z'/%3E%3C/svg%3E")
--dsc-chip-input-accent-colorvar(--ds-color-base-contrast-default)
--dsc-chip-input-colorvar(--ds-color-text-subtle)
--dsc-chip-input-sizevar(--ds-size-5)
--dsc-chip-input-stroke-colorvar(--ds-color-base-default)
--dsc-chip-padding-inlinevar(--ds-size-3)
--dsc-chip-spacingcalc((var(--dsc-chip-height) - var(--dsc-chip-input-size))/2)
--dsc-input-backgroundtransparent
--dsc-input-border-colorvar(--dsc-chip-input-color)
--dsc-input-accent-colorvar(--dsc-chip-input-accent-color)
--dsc-input-stroke-colorvar(--dsc-chip-input-stroke-color)
--dsc-input-size--togglevar(--dsc-chip-input-size)
--dsc-input-outline-width--hover0
Data Attributes
NameValue
data-wrapwrap
data-removable

React

command
Type
string
commandfor
Type
string
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
data-wrap
Description

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Type
"nowrap" | "wrap"
Default
'nowrap'
NameTypeDefaultDescription
commandstring-

-

commandforstring-

-

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

data-wrap"nowrap" | "wrap"'nowrap'

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

ChipRemovable

command
Type
string
commandfor
Type
string
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
data-wrap
Description

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Type
"nowrap" | "wrap"
Default
'nowrap'
NameTypeDefaultDescription
commandstring-

-

commandforstring-

-

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

data-wrap"nowrap" | "wrap"'nowrap'

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

ChipCheckbox

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
data-wrap
Description

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Type
"nowrap" | "wrap"
Default
'nowrap'
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

data-wrap"nowrap" | "wrap"'nowrap'

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

ChipRadio

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
data-wrap
Description

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Type
"nowrap" | "wrap"
Default
'nowrap'
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

data-wrap"nowrap" | "wrap"'nowrap'

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Edit this page on github.com (opens in a new tab)