@duskmoon-dev/el-chip

中文文档
1.10.3发布于 2026/11/11TypeScriptESM + CJS构建来源已验证近 30 天下载 2511

An accessible chip/tag custom element with display, link, action, selection, and removal modes.

原始使用文档
文档目录24 节
  1. Installation
  2. Usage
  3. Auto-Register
  4. Manual Registration
  5. Modes
  6. Variants
  7. Sizes
  8. Attributes
  9. Slots
  10. CSS Parts
  11. Events
  12. Examples
  13. Basic
  14. Semantic Modes
  15. Variants
  16. Colors
  17. Sizes
  18. Deletable
  19. Selectable
  20. Disabled
  21. With Icon
  22. Handling Delete
  23. Accessibility
  24. License

@duskmoon-dev/el-chip

An accessible chip/tag custom element with display, link, action, selection, and removal modes.

Installation

bun add @duskmoon-dev/el-chip

Usage

Auto-Register

import '@duskmoon-dev/el-chip/register';
<el-dm-chip>Label</el-dm-chip>

Manual Registration

import { ElDmChip, register } from '@duskmoon-dev/el-chip';

// Register with default tag name
register();

// Or register with custom tag name
customElements.define('my-chip', ElDmChip);

Modes

ModeEnable withRendered semanticsUse for
DisplayNo mode attributeNon-focusable <span>Static labels and tags
LinkhrefNative <a>Navigation
ClickableclickableNative <button type="button">One-off actions
SelectableselectableNative toggle button with aria-pressedFilters and choices
DeletabledeletableNoninteractive container with a native delete buttonRemovable tags

When multiple mode attributes are present, the mode precedence is deletable → href → selectable → clickable → display. This prevents nested interactive controls. Use one mode attribute per chip unless you intentionally rely on this precedence.

Variants

VariantDescription
filledFilled background (default)
outlinedOutlined style
softSoft/subtle background

Sizes

SizeDescription
smSmall chip
mdMedium chip (default)
lgLarge chip

Attributes

AttributeTypeDefaultDescription
variantstring'filled'Style variant
colorstring'primary'Color variant
sizestring'md'Size: sm, md, lg
hrefstring-Enables link mode and sets the link destination
targetstring-Link browsing context; used only with href
relstring-Link relationship; used only with href
clickablebooleanfalseEnables action-button mode
selectablebooleanfalseEnables toggle-button mode
deletablebooleanfalseShow delete button
delete-labelstring'Remove chip'Accessible name for the delete button (deleteLabel property)
selectedbooleanfalseSelected state; toggled automatically in selectable mode
disabledbooleanfalseDisabled state

Slots

SlotDescription
(default)Chip label
iconIcon before label

CSS Parts

PartDescription
chipThe chip element
iconThe icon container
deleteThe delete button

Events

EventDetailDescription
dm-click-Fired when a link or clickable chip is activated
dm-change{ selected: boolean }Fired after a selectable chip toggles
dm-delete-Fired when the delete button is activated
delete-Deprecated alias emitted with dm-delete

The custom events bubble, cross the shadow boundary, and are cancelable. Canceling dm-click prevents link navigation. Native click events from the rendered anchor or button are also available.

Examples

Basic

<el-dm-chip>Default</el-dm-chip>

Semantic Modes

<!-- Display -->
<el-dm-chip>Release 1.8</el-dm-chip>

<!-- Link -->
<el-dm-chip href="/releases" target="_blank" rel="noopener">Releases</el-dm-chip>

<!-- Action -->
<el-dm-chip clickable>Refresh</el-dm-chip>

<!-- Selection -->
<el-dm-chip selectable selected>TypeScript</el-dm-chip>

<!-- Removal -->
<el-dm-chip deletable delete-label="Remove TypeScript filter">TypeScript</el-dm-chip>

Variants

<el-dm-chip variant="filled">Filled</el-dm-chip>
<el-dm-chip variant="outlined">Outlined</el-dm-chip>
<el-dm-chip variant="soft">Soft</el-dm-chip>

Colors

<el-dm-chip color="primary">Primary</el-dm-chip>
<el-dm-chip color="success">Success</el-dm-chip>
<el-dm-chip color="warning">Warning</el-dm-chip>
<el-dm-chip color="error">Error</el-dm-chip>

Sizes

<el-dm-chip size="sm">Small</el-dm-chip>
<el-dm-chip size="md">Medium</el-dm-chip>
<el-dm-chip size="lg">Large</el-dm-chip>

Deletable

<el-dm-chip deletable delete-label="Remove Web Components tag">Web Components</el-dm-chip>

Selectable

<el-dm-chip selectable>Unselected</el-dm-chip> <el-dm-chip selectable selected>Selected</el-dm-chip>

Disabled

<el-dm-chip href="/releases" disabled>Unavailable link</el-dm-chip>
<el-dm-chip clickable disabled>Unavailable action</el-dm-chip>
<el-dm-chip selectable disabled>Unavailable choice</el-dm-chip>
<el-dm-chip deletable disabled>Protected tag</el-dm-chip>

With Icon

<el-dm-chip>
  <span slot="icon">⭐</span>
  Featured
</el-dm-chip>

Handling Delete

const chip = document.querySelector('el-dm-chip');
const filterInput = document.querySelector('#filter-input');
chip.addEventListener('dm-delete', () => {
  chip.remove();
  filterInput?.focus();
});

The component emits the removal request but never removes itself. If the application removes the focused chip, it must move focus to the next logical chip, the previous chip, or the owning input.

The legacy delete event remains available as a deprecated alias. New integrations should use dm-delete.

Accessibility

  • Display chips are plain, non-focusable text containers.
  • Link, clickable, and selectable modes use native anchor and button semantics, including their built-in keyboard behavior.
  • Selectable chips expose their state with aria-pressed and retain focus after toggling.
  • Deletable chips expose a focusable native button. Set delete-label when the default Remove chip name is not specific enough; the delete icon is hidden from assistive technology.
  • Disabled buttons use the native disabled state. A disabled link renders as a noninteractive span with aria-disabled="true", and disabled deletable chips disable their delete button.

License

MIT

版本与发布记录

@duskmoon-dev/el-chip 共发布 51 个版本,首次发布于 2026/01/13;过去 12 个月发布了 51 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.10.3latest2026/11/112 天前
1.10.22026/10/2222 天前
1.10.12026/10/1627 天前
1.10.02026/10/1628 天前
1.9.32026/10/131 个月前
1.9.22026/10/131 个月前

关于 @duskmoon-dev/el-chip 的常见问题

@duskmoon-dev/el-chip 是什么?

An accessible chip/tag custom element with display, link, action, selection, and removal modes.

如何安装 @duskmoon-dev/el-chip?

在项目目录运行 npm install @duskmoon-dev/el-chip,或使用 pnpm add / yarn add / bun add。

@duskmoon-dev/el-chip 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@duskmoon-dev/el-chip 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@duskmoon-dev/el-chip 可以商用吗?

@duskmoon-dev/el-chip 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@duskmoon-dev/el-chip 的下载量有多少?

根据 npm 官方下载统计,@duskmoon-dev/el-chip 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,511 次,日均约 84 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@duskmoon-dev/el-chip 还在维护吗?

最新版本 1.10.3 发布于 2026/11/11(2 天前);至今共发布 51 个版本,其中过去 12 个月发布了 51 个;首次发布于 2026/01/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。