@digdir/designsystemet-web

中文文档
1.24.0发布于 2026/11/09MITTypeScriptESM + CJS构建来源已验证近 30 天下载 6.6万

Javascript for Designsystemet

原始使用文档
文档目录24 节
  1. @digdir/designsystemet-web
  2. Table of contents
  3. Get started
  4. Pick the parts you need
  5. Individual imports
  6. Types
  7. Warnings:
  8. <ds-breadcrumbs>
  9. data-clickdelegatefor
  10. details and summary (accessibility polyfill)
  11. <dialog> ( closedby polyfill)
  12. Open and close
  13. <ds-error-summary>
  14. <ds-field>
  15. Counter
  16. fieldset
  17. invokers ( command polyfill)
  18. <ds-pagination>
  19. popover
  20. readonly
  21. <ds-suggestion>
  22. <ds-tabs>
  23. focusgroup (polyfill)
  24. data-tooltip

@digdir/designsystemet-web

Table of contents

Get started

@digdir/designsystemet-web provides framework-independent behaviour for Designsystemet components. It can be used together with @digdir/designsystemet-css, with your own CSS, or as a smaller enhancement layer in an existing setup.

We recommend importing the whole package when you want all web components, observers and polyfills available globally. This will register all web components and observers globally, so you only need to do this once.

import '@digdir/designsystemet-web';

See our documentation and patterns for more guidance. Pages are also available as Markdown by appending .md to the URL or requesting Accept: text/markdown.

Pick the parts you need

Designsystemet packages are meant to be used like a toolbox. You can use the full package, or only the parts that speed up your project.

For example, you can:

  • use @digdir/designsystemet-web without @digdir/designsystemet-css if you already have your own styling
  • use @digdir/designsystemet-css without @digdir/designsystemet-web if you only need styles and handle interactivity yourself
  • combine some Designsystemet components with your own components
  • build on top of the package where it helps, and skip the parts that do not fit your setup

Individual imports

The package supports sub-path exports which means you can import individual parts of the package if needed.

import '@digdir/designsystemet-web/ds-breadcrumbs';
import '@digdir/designsystemet-web/clickdelegatefor';
import '@digdir/designsystemet-web/details';
import '@digdir/designsystemet-web/dialog';
import '@digdir/designsystemet-web/ds-error-summary';
import '@digdir/designsystemet-web/ds-field';
import '@digdir/designsystemet-web/fieldset';
import '@digdir/designsystemet-web/focusgroup';
import '@digdir/designsystemet-web/invokers';
import '@digdir/designsystemet-web/ds-pagination';
import '@digdir/designsystemet-web/popover';
import '@digdir/designsystemet-web/readonly';
import '@digdir/designsystemet-web/ds-suggestion';
import '@digdir/designsystemet-web/ds-tabs';
import '@digdir/designsystemet-web/toggle-group';
import '@digdir/designsystemet-web/tooltip';

Types

Add the package to your types for types:

{
  "compilerOptions": {
    "types": ["@digdir/designsystemet-web"]
  }
}

Warnings:

@digdir/designsystemet-web will warn you about deprecations and missing attributes. This can come in handy while developing, but can also easily be hidden, for example in production:

import '@digdir/designsystemet-web';
if (typeof window !== 'undefined' && isProduction()) window.dsWarnings = false;

<ds-breadcrumbs>

Automatically hides/shows aria-label on desktop/mobile and aria-current="page" on last link in list. No API.

<ds-breadcrumbs class="ds-breadcrumbs" aria-label="You are here:">
  <a href="#none" aria-label="Back to level 3">
    Level 3
  </a>
  <ol>
    <li><a href="#none">Level 1</a></li>
    <li><a href="#none">Level 2</a></li>
    <li><a href="#none">Level 3</a></li>
  </ol>
</ds-breadcrumbs>

data-clickdelegatefor

Used for delegating click event. For example, you can use this to delegate click events from a parent element to child elements that are added dynamically.

<div class="ds-card" data-clickdelegatefor="target">
  <a id="target" href="https://example.com" rel="noopener">Go to example</a>
  <span>Clicking this card will open example in a new tab</span>
</div>

details and summary (accessibility polyfill)

Use native elements. We polyfill a bug in Firefox when combined with Android Talkback screen reader to announce state and role properly.

<details class="ds-details">
  <summary>More info</summary>
  <div>Lorem ipsum dolor sit amet.</div>
</details>

<dialog> (closedby polyfill)

Use the native <dialog> element. We polyfill support for closedby="any".

<dialog class="ds-dialog" closedby="any" id="my-dialog">
my dialog
</dialog>

Open and close

Use invokers command and commandfor, to open and close dialog.

<button class="ds-button" type="button" command="show-modal" commandfor="my-dialog">
  Open dialog
</button>
<dialog id="my-dialog" class="ds-dialog">
  <button class="ds-button" command="close" commandfor="my-dialog">Close</button>
</dialog>

<ds-error-summary>

Automatically takes focus when visible and sets aria-labelledby to the first child heading. No API.

<ds-error-summary class="ds-error-summary">
  <h2>Summary</h2>
  <ul>
    <li><a href="#none">Error 1</a></li>
    <li><a href="#none">Error 2</a></li>
    <li><a href="#none">Error 3</a></li>
  </ul>
</ds-error-summary>

<ds-field>

Connects inputs, labels and error messages.

<ds-field class="ds-field">
  <label>Label</label>
  <input type="text" placeholder="Placeholder" class="ds-input" />
  <div class="ds-validation-message" data-field="validation">
    This is a validation message.
  </div>
</ds-field>

Counter

You can add a counter to inputs and textareas by adding the data-field="counter" attribute to a <p> element inside a ds-field.

<ds-field class="ds-field">
  <label>Label</label>
  <textarea class="ds-input"></textarea>
  <p data-field="counter" data-limit="20" data-over="%d tegn for mye" data-under="%d tegn igjen"></p>
</ds-field>
attributetypedefaultrequired
data-limitnumberundefinedtrue
data-overstring%d tegn for myefalse
data-understring%d tegn igjenfalse

fieldset

An observer will look on fieldset element, add an id to combine children element with data-field="description" and legend into aria-labelledby on fieldset.

<fieldset>
    <legend>Delivery method</legend>
    <p data-field="description">Choose one option</p>
</fieldset>

invokers (command polyfill)

We automatically attach invokers-polyfill, which means that you get support for command and commandfor.

<ds-pagination>

Implements pagination, fills buttons with text. You can use both <a> and <button> elements inside the pagination.

If you don't pass any attributes you can implement your own logic for current page and total pages.

<ds-pagination class="ds-pagination" aria-label="Bla i sider:" data-href="?page=%d" data-current="2" data-total="100">
  <ol>
    <li><a>1</a></li>
    <li><a>2</a></li>
    <li><a>3</a></li>
    <li><a>4</a></li>
  </ol>
</ds-pagination>

popover

We use native popover functionality, but we attach an event listener that fixes placement of designsystem components.

<button class="ds-button" popovertarget="popover">Open popover</button>
<div class="ds-popover" popover id="popover" data-placement="left">
  This is some popover content. It can be very long, but it will wrap and
  stay within the viewport.
</div>
attributetypedefaultrequired
data-placementstringtopfalse
data-overscroll'contain' | undefinedundefinedfalse
data-autoplacementbooleantruefalse

If you don't use the class ds-popover you need to add the CSS property --_ds-floating to the popover element. This can be top, bottom, left or right.

readonly

Used for fixing readonly support on select and input elements. Add aria-readonly="true" to make the element behave as readonly, which means that it will not be editable by the user or call any change events.

<select aria-readonly="true">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
</select>

<ds-suggestion>

Extends u-combobox from u-elements. See documentation for u-combobox.

<ds-field class="ds-field">
  <label>Label</label>
  <ds-suggestion class="ds-suggestion">
    <input type="search" class="ds-input" />
    <del aria-label="Fjern innhold"></del>
    <u-datalist>
      <u-option value="option-1">Option 1</u-option>
      <u-option value="option-2">Option 2</u-option>
      <u-option value="option-3">Option 3</u-option>
    </u-datalist>
  </ds-suggestion>
</ds-field>

<ds-tabs>

Extends u-tabs from u-elements. See documentation for u-tabs.

<ds-tabs class="ds-tabs">
  <ds-tablist>
    <ds-tab>Tab 1</ds-tab>
    <ds-tab>Tab 2</ds-tab>
    <ds-tab>Tab 3</ds-tab>
  </ds-tablist>
  <ds-tabpanel>Panel 1</ds-tabpanel>
  <ds-tabpanel>Panel 2</ds-tabpanel>
  <ds-tabpanel>Panel 3</ds-tabpanel>
</ds-tabs>

focusgroup (polyfill)

focusgroup is polyfilled according to upcoming specification.

<fieldset class="ds-toggle-group" focusgroup="radiogroup" aria-label="Tekstjustering" data-variant="secondary">
  <label class="ds-button">
    <input type="radio" name="alignment" value="left" checked />
    Left
  </label>
  <label class="ds-button">
    <input type="radio" name="alignment" value="center" />
    Center
  </label>
  <label class="ds-button">
    <input type="radio" name="alignment" value="right" />
    Right
  </label>
</fieldset>

Radio inputs in a focusgroup="radiogroup", like the toggle group above, are handled by toggle-group: the arrow keys move focus without selecting, and Enter selects. It also migrates the deprecated data-toggle-group attribute to focusgroup="radiogroup", with a warning.

data-tooltip

Using a single element for rendering next to elements with data-tooltip attribute. Also automatically sets aria-label or aria-description as needed. Uses native popover functionality with our popover polyfill.

<button data-placement="left" data-tooltip="left" class="ds-button">left</button>

版本与发布记录

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

版本发布日期距今
1.24.0latest2026/11/092 天前
0.0.0-spike-flatter-design-tokens-20261020130336test2026/10/2022 天前
0.0.0-main-20261016102511next2026/10/1626 天前
0.0.0-config-output-types-202610011312182026/10/011 个月前
0.0.0-config-output-types-202609300936302026/09/301 个月前
1.23.02026/09/251 个月前

关于 @digdir/designsystemet-web 的常见问题

@digdir/designsystemet-web 是什么?

Javascript for Designsystemet

如何安装 @digdir/designsystemet-web?

在项目目录运行 npm install @digdir/designsystemet-web,或使用 pnpm add / yarn add / bun add。

@digdir/designsystemet-web 支持 TypeScript 吗?

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

@digdir/designsystemet-web 支持 ESM 还是 CommonJS?

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

@digdir/designsystemet-web 可以商用吗?

@digdir/designsystemet-web 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@digdir/designsystemet-web 的下载量有多少?

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

@digdir/designsystemet-web 还在维护吗?

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