From d2e9de9511e2bda4c5f0d08f4cf220b748e63ae2 Mon Sep 17 00:00:00 2001
From: JeremyWuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com>
Date: Tue, 22 Feb 2022 12:49:28 +0800
Subject: [PATCH] feat(components): [el-dialog] enhancement for dialog a11y
(#6087)
* feat(components): [el-dialog] enhancement for dialog a11y
- Refactor dialog to script setup
* Separates dialog and its content into different components
* Remove unused code & fix a potential bug in focus-trap component
* Update dialog-content.vue
Co-authored-by: bqy <1743369777@qq.com>
---
docs/en-US/component/dialog.md | 30 +++-
docs/examples/dialog/focus-trapping.vue | 47 ++++++
.../dialog/__tests__/dialog.spec.ts | 10 +-
.../components/dialog/src/dialog-content.ts | 32 ++++
.../components/dialog/src/dialog-content.vue | 65 ++++++++
packages/components/dialog/src/dialog.ts | 40 ++---
packages/components/dialog/src/dialog.vue | 153 +++++++++---------
packages/components/dialog/src/token.ts | 14 ++
.../focus-trap/__tests__/focus-trap.spec.ts | 43 +++--
.../components/focus-trap/src/focus-trap.vue | 40 +++--
packages/theme-chalk/src/dialog.scss | 8 +-
11 files changed, 323 insertions(+), 159 deletions(-)
create mode 100644 docs/examples/dialog/focus-trapping.vue
create mode 100644 packages/components/dialog/src/dialog-content.ts
create mode 100644 packages/components/dialog/src/dialog-content.vue
create mode 100644 packages/components/dialog/src/token.ts
diff --git a/docs/en-US/component/dialog.md b/docs/en-US/component/dialog.md
index 93bbf62c0a..1110204a15 100644
--- a/docs/en-US/component/dialog.md
+++ b/docs/en-US/component/dialog.md
@@ -23,6 +23,22 @@ dialog/basic-usage
:::
+## Focus trapping
+
+Dialog traps focus inside the dialog content which enables your users to navigate the content via keyboard.
+
+:::tip
+
+Focusing on other element after the dialog is closed will only work when `destroy-on-close` is enabled
+
+:::
+
+:::demo
+
+dialog/focus-trapping
+
+:::
+
## Customizations
The content of Dialog can be anything, even a table or a form. This example shows how to use Element Plus Table and Form with Dialog。
@@ -118,9 +134,11 @@ When using `modal` = false, please make sure that `append-to-body` was set to **
## Events
-| Event Name | Description | Parameters |
-| ---------- | ----------------------------------------------- | ---------- |
-| open | triggers when the Dialog opens | — |
-| opened | triggers when the Dialog opening animation ends | — |
-| close | triggers when the Dialog closes | — |
-| closed | triggers when the Dialog closing animation ends | — |
+| Event Name | Description | Parameters |
+| ---------------- | ------------------------------------------------ | ---------- |
+| open | triggers when the Dialog opens | — |
+| opened | triggers when the Dialog opening animation ends | — |
+| close | triggers when the Dialog closes | — |
+| closed | triggers when the Dialog closing animation ends | — |
+| open-auto-focus | triggers after Dialog opens and content focused | — |
+| close-auto-focus | triggers after Dialog closed and content focused | — |
diff --git a/docs/examples/dialog/focus-trapping.vue b/docs/examples/dialog/focus-trapping.vue
new file mode 100644
index 0000000000..002d1da1ad
--- /dev/null
+++ b/docs/examples/dialog/focus-trapping.vue
@@ -0,0 +1,47 @@
+
+ click to open the Dialog
+
+