胶囊标签
胶囊形控件,用作可切换的筛选条件或可移除的值。
本页内容
胶囊标签(Chip)是一种紧凑控件,用于表示选项或值,两端呈半圆形。徽标用于说明信息,胶囊标签则可供操作。用作筛选条件时,胶囊标签用 <label> 包裹原生复选框或单选按钮,未选中时呈凸起效果,选中后填充墨色,填充方式与复选框相同。
胶囊标签
<fieldset class="flex flex-wrap gap-xs m(0) p(0) b(0)"> <legend class="mb-xs text-sm fg-text-strong">Topics</legend> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="design" checked>Design </label> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="engineering">Engineering </label> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="research" checked>Research </label> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="legal" disabled>Legal </label></fieldset><fieldset className="flex flex-wrap gap-xs m(0) p(0) b(0)"> <legend className="mb-xs text-sm fg-text-strong">Topics</legend> <label className="chip"> <input type="checkbox" className="chip-input" name="topic" value="design" defaultChecked />Design </label> <label className="chip"> <input type="checkbox" className="chip-input" name="topic" value="engineering" />Engineering </label> <label className="chip"> <input type="checkbox" className="chip-input" name="topic" value="research" defaultChecked />Research </label> <label className="chip"> <input type="checkbox" className="chip-input" name="topic" value="legal" disabled />Legal </label></fieldset><fieldset class="flex flex-wrap gap-xs m(0) p(0) b(0)"> <legend class="mb-xs text-sm fg-text-strong">Topics</legend> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="design" checked>Design </label> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="engineering">Engineering </label> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="research" checked>Research </label> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="legal" disabled>Legal </label></fieldset><template> <fieldset class="flex flex-wrap gap-xs m(0) p(0) b(0)"> <legend class="mb-xs text-sm fg-text-strong">Topics</legend> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="design" checked>Design </label> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="engineering">Engineering </label> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="research" checked>Research </label> <label class="chip"> <input type="checkbox" class="chip-input" name="topic" value="legal" disabled>Legal </label> </fieldset></template>#多项中选一项
单选按钮共用同一个 name 时,这组胶囊标签只能选中一项,可用方向键在各项之间切换。选项较少且选择后立即更新视图时,可用这种方式。为表单字段选择值时,分段控件在视觉上更像一个整体控件。
多项中选一项
<div class="flex flex-wrap gap-xs" role="radiogroup" aria-label="Period"> <label class="chip"><input type="radio" class="chip-input" name="period" checked>Today</label> <label class="chip"><input type="radio" class="chip-input" name="period">7 days</label> <label class="chip"><input type="radio" class="chip-input" name="period">30 days</label> <label class="chip"><input type="radio" class="chip-input" name="period">All time</label></div><div className="flex flex-wrap gap-xs" role="radiogroup" aria-label="Period"> <label className="chip"> <input type="radio" className="chip-input" name="period" defaultChecked />Today </label> <label className="chip"><input type="radio" className="chip-input" name="period" />7 days</label> <label className="chip"><input type="radio" className="chip-input" name="period" />30 days</label> <label className="chip"> <input type="radio" className="chip-input" name="period" />All time </label></div><div class="flex flex-wrap gap-xs" role="radiogroup" aria-label="Period"> <label class="chip"><input type="radio" class="chip-input" name="period" checked>Today</label> <label class="chip"><input type="radio" class="chip-input" name="period">7 days</label> <label class="chip"><input type="radio" class="chip-input" name="period">30 days</label> <label class="chip"><input type="radio" class="chip-input" name="period">All time</label></div><template> <div class="flex flex-wrap gap-xs" role="radiogroup" aria-label="Period"> <label class="chip"><input type="radio" class="chip-input" name="period" checked>Today</label> <label class="chip"><input type="radio" class="chip-input" name="period">7 days</label> <label class="chip"><input type="radio" class="chip-input" name="period">30 days</label> <label class="chip"><input type="radio" class="chip-input" name="period">All time</label> </div></template>#值
胶囊标签不含输入控件时表示一个值,例如收件人、标签或已应用的筛选条件。它采用胶囊标签的色调,并以一道轮廓线勾勒。chip-remove 是末端的圆形按钮,其无障碍名称应包含该值。为前置图标设置 icon。
值
<span class="chip"> ada@example.com<button type="button" class="chip-remove" aria-label="Remove ada@example.com"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button></span><span class="chip"> alan@example.com<button type="button" class="chip-remove" aria-label="Remove alan@example.com"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button></span><span class="chip"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" /> </svg> Status: Ready</span>import XIcon from '@master/icons-react/native/16/soft/x'import FilterIcon from '@master/icons-react/native/16/soft/filter'<> <span className="chip"> ada@example.com<button type="button" className="chip-remove" aria-label="Remove ada@example.com"> <XIcon className="icon" /> </button> </span> <span className="chip"> alan@example.com<button type="button" className="chip-remove" aria-label="Remove alan@example.com"> <XIcon className="icon" /> </button> </span> <span className="chip"><FilterIcon className="icon" /> Status: Ready</span></><script> import XIcon from '@master/icons-svelte/native/16/soft/x' import FilterIcon from '@master/icons-svelte/native/16/soft/filter'</script><span class="chip"> ada@example.com<button type="button" class="chip-remove" aria-label="Remove ada@example.com"> <XIcon class="icon" /> </button></span><span class="chip"> alan@example.com<button type="button" class="chip-remove" aria-label="Remove alan@example.com"> <XIcon class="icon" /> </button></span><span class="chip"><FilterIcon class="icon" /> Status: Ready</span><script setup>import XIcon from '@master/icons-vue/native/16/soft/x'import FilterIcon from '@master/icons-vue/native/16/soft/filter'</script><template> <span class="chip"> ada@example.com<button type="button" class="chip-remove" aria-label="Remove ada@example.com"> <XIcon class="icon" /> </button> </span> <span class="chip"> alan@example.com<button type="button" class="chip-remove" aria-label="Remove alan@example.com"> <XIcon class="icon" /> </button> </span> <span class="chip"><FilterIcon class="icon" /> Status: Ready</span></template>#图片、圆点和计数
胶囊标签可以依次包含:一张图片(chip-media、头像或图标,由胶囊标签设置尺寸和圆角)、一个分类圆点(chip-dot)、文字(chip-label)、一个计数(带 chip-count 的徽标)和一个移除按钮(chip-remove,内含其图标)。空间不足时,文字最先收缩并以省略号结尾;图片、计数和按钮保持尺寸不变。开头的图片和末尾的计数与胶囊端部的距离,等于它们与上下边缘的距离,因此弧线是同心的。
图片、圆点和计数
<span class="chip"> <span class="chip-media"> <span class="avatar"><img class="avatar-image" src="/demo/portrait-1.svg" alt></span> </span><span class="chip-label">Ada Lovelace</span><button type="button" class="chip-remove" aria-label="Remove Ada Lovelace"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button></span><span class="chip"> <span class="chip-media"><span class="avatar" aria-hidden="true">GH</span></span><span class="chip-label">Grace Hopper</span><button type="button" class="chip-remove" aria-label="Remove Grace Hopper"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button></span><span class="chip max-w(176)" title="Accessibility review for the checkout"> <span class="chip-dot"></span><span class="chip-label">Accessibility review for the checkout</span><span class="badge chip-count">12</span></span>import XIcon from '@master/icons-react/native/16/soft/x'<> <span className="chip"> <span className="chip-media"> <span className="avatar"> <img className="avatar-image" src="/demo/portrait-1.svg" alt="" /> </span> </span><span className="chip-label">Ada Lovelace</span><button type="button" className="chip-remove" aria-label="Remove Ada Lovelace"> <XIcon className="icon" /> </button> </span> <span className="chip"> <span className="chip-media"><span className="avatar" aria-hidden="true">GH</span></span><span className="chip-label">Grace Hopper</span><button type="button" className="chip-remove" aria-label="Remove Grace Hopper"> <XIcon className="icon" /> </button> </span> <span className="chip max-w(176)" title="Accessibility review for the checkout"> <span className="chip-dot"></span><span className="chip-label">Accessibility review for the checkout</span><span className="badge chip-count">12</span> </span></><script> import XIcon from '@master/icons-svelte/native/16/soft/x'</script><span class="chip"> <span class="chip-media"> <span class="avatar"><img class="avatar-image" src="/demo/portrait-1.svg" alt></span> </span><span class="chip-label">Ada Lovelace</span><button type="button" class="chip-remove" aria-label="Remove Ada Lovelace"> <XIcon class="icon" /> </button></span><span class="chip"> <span class="chip-media"><span class="avatar" aria-hidden="true">GH</span></span><span class="chip-label">Grace Hopper</span><button type="button" class="chip-remove" aria-label="Remove Grace Hopper"> <XIcon class="icon" /> </button></span><span class="chip max-w(176)" title="Accessibility review for the checkout"> <span class="chip-dot"></span><span class="chip-label">Accessibility review for the checkout</span><span class="badge chip-count">12</span></span><script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template> <span class="chip"> <span class="chip-media"> <span class="avatar"><img class="avatar-image" src="/demo/portrait-1.svg" alt></span> </span><span class="chip-label">Ada Lovelace</span><button type="button" class="chip-remove" aria-label="Remove Ada Lovelace"> <XIcon class="icon" /> </button> </span> <span class="chip"> <span class="chip-media"><span class="avatar" aria-hidden="true">GH</span></span><span class="chip-label">Grace Hopper</span><button type="button" class="chip-remove" aria-label="Remove Grace Hopper"> <XIcon class="icon" /> </button> </span> <span class="chip max-w(176)" title="Accessibility review for the checkout"> <span class="chip-dot"></span><span class="chip-label">Accessibility review for the checkout</span><span class="badge chip-count">12</span> </span></template>计数是一个徽标,因此保留徽标的材质;在已选中的筛选标签上,它改用墨色的一种色调。
筛选标签上的计数
<div class="flex flex-wrap gap-xs" role="group" aria-label="Status"> <label class="chip"> <input type="checkbox" class="chip-input" checked>Open <span class="badge chip-count">24</span> </label> <label class="chip"> <input type="checkbox" class="chip-input">In review <span class="badge chip-count">7</span> </label> <label class="chip"> <input type="checkbox" class="chip-input">Closed <span class="badge chip-count">132</span> </label></div><div className="flex flex-wrap gap-xs" role="group" aria-label="Status"> <label className="chip"> <input type="checkbox" className="chip-input" defaultChecked />Open <span className="badge chip-count">24</span> </label> <label className="chip"> <input type="checkbox" className="chip-input" />In review <span className="badge chip-count">7</span> </label> <label className="chip"> <input type="checkbox" className="chip-input" />Closed <span className="badge chip-count">132</span> </label></div><div class="flex flex-wrap gap-xs" role="group" aria-label="Status"> <label class="chip"> <input type="checkbox" class="chip-input" checked>Open <span class="badge chip-count">24</span> </label> <label class="chip"> <input type="checkbox" class="chip-input">In review <span class="badge chip-count">7</span> </label> <label class="chip"> <input type="checkbox" class="chip-input">Closed <span class="badge chip-count">132</span> </label></div><template> <div class="flex flex-wrap gap-xs" role="group" aria-label="Status"> <label class="chip"> <input type="checkbox" class="chip-input" checked>Open <span class="badge chip-count">24</span> </label> <label class="chip"> <input type="checkbox" class="chip-input">In review <span class="badge chip-count">7</span> </label> <label class="chip"> <input type="checkbox" class="chip-input">Closed <span class="badge chip-count">132</span> </label> </div></template>筛选标签是包裹其输入控件的 label,整个胶囊标签都是操作目标,因此不要在其中放移除按钮。可移除的值应使用带 chip-remove 的普通胶囊标签。
#分类
chip-category 读取胶囊标签自身或其外层设置的分类色。值使用该分类的底色、文字颜色和描边。筛选标签保持凸起的外观,选中时保持墨色,因此在任何分类中,选中状态看起来都一样;分类由它的 chip-dot 体现。
分类
<div class="flex flex-col items-center gap-sm"> <div class="flex flex-wrap justify-center gap-xs"> <span class="chip chip-category category-violet"> <span class="chip-dot"></span>Research<button type="button" class="chip-remove" aria-label="Remove Research"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </span> <span class="chip chip-category category-teal"> <span class="chip-dot"></span>Design system<button type="button" class="chip-remove" aria-label="Remove Design system"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </span> </div> <div class="flex flex-wrap justify-center gap-xs" role="group" aria-label="Projects"> <label class="chip chip-category category-violet"> <input type="checkbox" class="chip-input" checked><span class="chip-dot"></span>Research </label> <label class="chip chip-category category-teal"> <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Design system </label> <label class="chip chip-category category-orange"> <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Launch </label> </div></div>import XIcon from '@master/icons-react/native/16/soft/x'<div className="flex flex-col items-center gap-sm"> <div className="flex flex-wrap justify-center gap-xs"> <span className="chip chip-category category-violet"> <span className="chip-dot"></span>Research<button type="button" className="chip-remove" aria-label="Remove Research"> <XIcon className="icon" /> </button> </span> <span className="chip chip-category category-teal"> <span className="chip-dot"></span>Design system<button type="button" className="chip-remove" aria-label="Remove Design system"> <XIcon className="icon" /> </button> </span> </div> <div className="flex flex-wrap justify-center gap-xs" role="group" aria-label="Projects"> <label className="chip chip-category category-violet"> <input type="checkbox" className="chip-input" defaultChecked /><span className="chip-dot"></span>Research </label> <label className="chip chip-category category-teal"> <input type="checkbox" className="chip-input" /><span className="chip-dot"></span>Design system </label> <label className="chip chip-category category-orange"> <input type="checkbox" className="chip-input" /><span className="chip-dot"></span>Launch </label> </div></div><script> import XIcon from '@master/icons-svelte/native/16/soft/x'</script><div class="flex flex-col items-center gap-sm"> <div class="flex flex-wrap justify-center gap-xs"> <span class="chip chip-category category-violet"> <span class="chip-dot"></span>Research<button type="button" class="chip-remove" aria-label="Remove Research"> <XIcon class="icon" /> </button> </span> <span class="chip chip-category category-teal"> <span class="chip-dot"></span>Design system<button type="button" class="chip-remove" aria-label="Remove Design system"> <XIcon class="icon" /> </button> </span> </div> <div class="flex flex-wrap justify-center gap-xs" role="group" aria-label="Projects"> <label class="chip chip-category category-violet"> <input type="checkbox" class="chip-input" checked><span class="chip-dot"></span>Research </label> <label class="chip chip-category category-teal"> <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Design system </label> <label class="chip chip-category category-orange"> <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Launch </label> </div></div><script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template> <div class="flex flex-col items-center gap-sm"> <div class="flex flex-wrap justify-center gap-xs"> <span class="chip chip-category category-violet"> <span class="chip-dot"></span>Research<button type="button" class="chip-remove" aria-label="Remove Research"> <XIcon class="icon" /> </button> </span> <span class="chip chip-category category-teal"> <span class="chip-dot"></span>Design system<button type="button" class="chip-remove" aria-label="Remove Design system"> <XIcon class="icon" /> </button> </span> </div> <div class="flex flex-wrap justify-center gap-xs" role="group" aria-label="Projects"> <label class="chip chip-category category-violet"> <input type="checkbox" class="chip-input" checked><span class="chip-dot"></span>Research </label> <label class="chip chip-category category-teal"> <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Design system </label> <label class="chip chip-category category-orange"> <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Launch </label> </div> </div></template>#尺寸
chip-sm 为 24px,chip-lg 为 32px,默认为 28px。移除按钮、图片和计数随之缩放。在触屏上,胶囊标签保持原有高度:筛选标签的操作区域在胶囊周围扩展至 44px,移除按钮的操作区域在所属的值内高达 44px。容纳多个值的输入框(例如标签输入)会自行设置其中值的高度。
尺寸
<span class="chip chip-sm"> <span class="chip-dot"></span>Small<button type="button" class="chip-remove" aria-label="Remove Small"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button></span><span class="chip"> <span class="chip-dot"></span>Medium<button type="button" class="chip-remove" aria-label="Remove Medium"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button></span><span class="chip chip-lg"> <span class="chip-dot"></span>Large<button type="button" class="chip-remove" aria-label="Remove Large"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button></span>import XIcon from '@master/icons-react/native/16/soft/x'<> <span className="chip chip-sm"> <span className="chip-dot"></span>Small<button type="button" className="chip-remove" aria-label="Remove Small"> <XIcon className="icon" /> </button> </span> <span className="chip"> <span className="chip-dot"></span>Medium<button type="button" className="chip-remove" aria-label="Remove Medium"> <XIcon className="icon" /> </button> </span> <span className="chip chip-lg"> <span className="chip-dot"></span>Large<button type="button" className="chip-remove" aria-label="Remove Large"> <XIcon className="icon" /> </button> </span></><script> import XIcon from '@master/icons-svelte/native/16/soft/x'</script><span class="chip chip-sm"> <span class="chip-dot"></span>Small<button type="button" class="chip-remove" aria-label="Remove Small"> <XIcon class="icon" /> </button></span><span class="chip"> <span class="chip-dot"></span>Medium<button type="button" class="chip-remove" aria-label="Remove Medium"> <XIcon class="icon" /> </button></span><span class="chip chip-lg"> <span class="chip-dot"></span>Large<button type="button" class="chip-remove" aria-label="Remove Large"> <XIcon class="icon" /> </button></span><script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template> <span class="chip chip-sm"> <span class="chip-dot"></span>Small<button type="button" class="chip-remove" aria-label="Remove Small"> <XIcon class="icon" /> </button> </span> <span class="chip"> <span class="chip-dot"></span>Medium<button type="button" class="chip-remove" aria-label="Remove Medium"> <XIcon class="icon" /> </button> </span> <span class="chip chip-lg"> <span class="chip-dot"></span>Large<button type="button" class="chip-remove" aria-label="Remove Large"> <XIcon class="icon" /> </button> </span></template>#无障碍
- 筛选标签内的输入控件不可见,但覆盖整个胶囊标签,因此整个标签都是操作目标,状态、键盘操作和表单值由输入控件负责。使用带
<legend>的<fieldset>,或带标签的role="radiogroup",将筛选标签分组。 - 移除按钮的操作区域超出其图标,图标位置保持不变。操作区域为 28px,在触屏上高 44px,但不会超出所属的值的末端。
- 分类圆点仅作装饰,分类名称由胶囊标签的文字说明。
- 选中的胶囊标签在 Moonstone 中填充墨色,在 Obsidian 中填充珍珠色,均以明暗区分,因此无需辨别色相。
#类名
| 类名 | 说明 |
|---|---|
chip | 胶囊标签高 28px,可以是包裹 chip-input 的 label,也可以是容纳值的普通元素。使用触控时,筛选胶囊标签和移除按钮的触控区域均为 44px 高,胶囊标签本身保持原有高度。 |
chip-sm | 高 24px;默认为 28px与 chip 一同使用 |
chip-lg | 高 32px;默认为 28px与 chip 一同使用 |
chip-category | 值型胶囊标签使用自身或外层的 category-<name> 类所指定分类的背景色、文字色和边框色。筛选胶囊标签保留原有外观,通过 chip-dot 表示分类。与 chip 一同使用 |
chip-input | 筛选胶囊标签内的复选框或单选按钮。它以透明方式覆盖整个胶囊标签,操作目标是 label,选中状态由 input 保存。 |
chip-remove | 位于值末尾的圆形移除按钮,内含其图标,无障碍名称包含该值 |
chip-label | 文字:空间不足时最先收缩并以省略号结尾,图片、计数和移除按钮保持原有尺寸 |
chip-media | 位于开头的圆形图片,直径为胶囊标签高度减去两倍内缩距离:可放头像或图标,并由它决定其尺寸 |
chip-dot | 8px 圆点,使用分类的标记色,没有分类时使用弱化墨色;仅作装饰,因此由标签文字说明分类 |
chip-count | 用于胶囊标签内的徽标,使徽标呈与胶囊标签同心的胶囊形,并在筛选胶囊标签选中时使用墨色调。 |
#自定义属性
| 属性 | 默认值 | 说明 |
|---|---|---|
--chip-height | 1.75rem | 高度;容纳值的输入框会为其凹槽中的胶囊标签设置此值 |
--chip-inset | .25rem | chip-media 或 chip-count 与胶囊标签末端之间的内缩距离 |