@fylgja/alpinejs-dialog

中文文档
2.3.0发布于 2026/06/08MITESM + CJS零依赖近 30 天下载 3223

Bring the power of AlpineJs to the HTML dialog

原始使用文档
文档目录5 节
  1. Installation
  2. Via NPM
  3. Via CDN
  4. Usage
  5. Modifiers

Fylgja - AlpineJS Dialog

NPM version License Netlify Status

Bring the power and simplicity of Alpine.js to the native HTML <dialog> element.

Live Demo: https://alpinejs-dialog.netlify.app/

Installation

You can use this plugin by either installing it using NPM or including it from a CDN.

Via NPM

You can install it from NPM and include it in your bundle:

npm install @fylgja/alpinejs-dialog
import Alpine from 'alpinejs';
import dialog from '@fylgja/alpinejs-dialog';

window.Alpine = Alpine;

Alpine.plugin(dialog);
Alpine.start();

Via CDN

You can include the CDN version of this plugin as a <script> tag, just make sure to include it before AlpineJs.

<script defer src="https://unpkg.com/@fylgja/alpinejs-dialog/dist/index.min.js"></script>
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>

Usage

To utilize the x-htmldialog plugin, add the directive to an HTML <dialog> element that is also controlled by x-show.

<div x-data="{ open: false }">
    <button @click="open = !open">Open</button>
    <dialog x-show="open" x-htmldialog="open = false">..</dialog>
</div>

When the x-htmldialog directive is present on an x-show element:

  • It prevents x-show from directly toggling the display style.
  • Instead, it uses the native el.showModal() function to display the dialog.
  • The optional value provided to x-htmldialog (e.g., "open = false") is executed when the dialog is closed by pressing the Escape key or clicking outside the dialog (the backdrop).

Modifiers

The x-htmldialog directive supports modifiers to further customize its behavior.

noscroll

The noscroll modifier prevents scrolling on the background page while the dialog is open.

<div x-data="{ open: false }">
    <button @click="open = !open">Open</button>
    <dialog x-show="open" x-htmldialog.noscroll="open = false">..</dialog>
</div>

closeby

The closeby option gives you fine-grained control over how the dialog can be dismissed. The plugin polyfills this behavior for browsers that do not yet support it natively.

You can set this option in two ways:

1. As an attribute on the <dialog> element:

<dialog closeby="any" ...>

2. As a modifier on the x-htmldialog directive:

<dialog x-htmldialog.closeby.any ...>

Available Options

  • any: The dialog can be closed by any user action, such as pressing the ESC key or clicking on the backdrop.
  • closerequest: (Default) The dialog can be dismissed via the ESC key or a "close request" (e.g., a form submission with method="dialog"). It will not close when the backdrop is clicked.
  • none: The user cannot close the dialog. It must be closed programmatically.

modeless

The modeless modifier opens the dialog as a non-modal dialog using el.show() instead of el.showModal(). This means it does not block interaction with the rest of the page and does not render a backdrop.

<dialog x-htmldialog.modeless ...>

版本与发布记录

@fylgja/alpinejs-dialog 共发布 13 个版本,首次发布于 2022/09/16;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.3.0latest2026/06/085 个月前
2.2.32025/10/161.1 年前
2.2.22025/10/161.1 年前
2.2.12025/09/101.2 年前
2.2.02025/09/101.2 年前
2.1.12025/05/091.5 年前

关于 @fylgja/alpinejs-dialog 的常见问题

@fylgja/alpinejs-dialog 是什么?

Bring the power of AlpineJs to the HTML dialog

如何安装 @fylgja/alpinejs-dialog?

在项目目录运行 npm install @fylgja/alpinejs-dialog,或使用 pnpm add / yarn add / bun add。

@fylgja/alpinejs-dialog 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fylgja__alpinejs-dialog 是否存在。

@fylgja/alpinejs-dialog 支持 ESM 还是 CommonJS?

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

@fylgja/alpinejs-dialog 可以商用吗?

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

@fylgja/alpinejs-dialog 的下载量有多少?

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

@fylgja/alpinejs-dialog 还在维护吗?

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