# Focus-Trapped Modal Kit

https://fieldbook.lizardi.mx/zh/components/focus-trapped-modal-kit

分类：叠加层
缩略图：https://fieldbook.lizardi.mx/thumbs/focus-trapped-modal-kit.webp

Focus-Trapped Modal Kit：精简模态框基础组件，重点提供严谨的键盘行为：打开时限制焦点范围，关闭时准确恢复焦点，并带倾斜入场效果。

## 框架

react、vue、svelte、astro、html

## 预览控件

这些控件会传给演示组件。默认值和限制描述的是预览；完整的属性接口请查看实现代码。

| 名称 | 类型 | 默认值 | 选项或限制 |
| --- | --- | --- | --- |
| from | select | top | 选项：top、bottom、left、right |
| trapFocus | boolean | true | 元数据未列出其他限制。 |
| accent | color | #F5C542 | 元数据未列出其他限制。 |
| label | text | Session settings | 最多 50 个字符 |

## 使用说明

Focus-Trapped Modal Kit 的预览采用「卡片」布局，主题设置为「浅色/深色」。

### Focus-Trapped Modal Kit 提供哪些框架版本？

Focus-Trapped Modal Kit 提供 React、Vue、Svelte、Astro、HTML 版本。实时预览使用 React；以下代码观察仅针对 index.tsx。使用其他版本前，请确认其交互行为。

### Focus-Trapped Modal Kit 有哪些依赖？

React 元数据列出的额外 npm 依赖为：motion、clsx、tailwind-merge。

### Focus-Trapped Modal Kit 的代码中有哪些无障碍细节？

Focus-Trapped Modal Kit 的 React 代码包含：原生元素（button）；属性与事件处理器（aria-checked、aria-hidden、aria-label、aria-modal、onKeyDown、tabIndex）；显式角色（dialog、switch）；按键比较（Escape、Tab）。这些信息来自代码观察。请在组合后的页面中验证无障碍名称、焦点顺序和键盘行为。

### Focus-Trapped Modal Kit 如何处理减少动态效果的偏好？

Focus-Trapped Modal Kit 的 React 代码通过 useReducedMotion() 读取动态效果偏好。index.tsx 中随偏好变化的表达式：duration: reduced ? 0 : 0.18；enter: reduced ? \{ duration: 0.14 \} : \{ type: "spring", stiffness: 260, damping: 24, mass: 0.85 \}；exit: reduced ? \{ duration: 0.1 \} : \{ duration: 0.16, ease: \[0.4, 0, 1, 1\] \}。请启用减少动态效果，检查完整实现、共享样式和所选框架版本；这些观察不能证明所有动画都会停止。

## 通过 MCP 安装

连接客户端，调用 get_component 获取实现，再调用 get_install_command 获取安装说明。选择已列出的框架，将源代码集成到应用中并验证功能。

```json
{
  "tool": "get_component",
  "arguments": {
    "slug": "focus-trapped-modal-kit",
    "framework": "react"
  }
}
```

[面向智能体](https://fieldbook.lizardi.mx/zh/docs/agents)
[MCP](https://fieldbook.lizardi.mx/api/mcp)

## 相关开放组件

- [Bounce warning dialog](https://fieldbook.lizardi.mx/zh/components/bounce-warning-dialog)
- [Centered modal frame](https://fieldbook.lizardi.mx/zh/components/centered-modal-frame)
- [Confirm action modal](https://fieldbook.lizardi.mx/zh/components/confirm-action-modal)
- [Consequence confirm dialog](https://fieldbook.lizardi.mx/zh/components/consequence-confirm-dialog)
- [Destructive confirm dialog](https://fieldbook.lizardi.mx/zh/components/destructive-confirm-dialog)
- [Perspective reveal dialog](https://fieldbook.lizardi.mx/zh/components/perspective-reveal-dialog)
