diff --git a/examples/sites/demos/pc/app/dialog-box/basic-usage.spec.ts b/examples/sites/demos/pc/app/dialog-box/basic-usage.spec.ts index cca44cd4cc..f3f5b5eb0d 100644 --- a/examples/sites/demos/pc/app/dialog-box/basic-usage.spec.ts +++ b/examples/sites/demos/pc/app/dialog-box/basic-usage.spec.ts @@ -5,22 +5,22 @@ test('dialogBox 基础用法', async ({ page }) => { await page.goto('dialog-box#basic-usage') const demo = page.locator('#basic-usage') - await page.getByRole('button', { name: /Dialog/ }).click() + await demo.getByRole('button', { name: /Dialog/ }).click() await demo.getByRole('button', { name: '确 定' }).click() - await page.getByRole('button', { name: /Dialog/ }).click() + await demo.getByRole('button', { name: /Dialog/ }).click() await demo.getByRole('button', { name: '取 消' }).click() // 点击 x 图标 - await page.getByRole('button', { name: /Dialog/ }).click() + await demo.getByRole('button', { name: /Dialog/ }).click() await demo.getByLabel('Close').click() // 点击遮罩时,关闭 dialogBox - await page.getByRole('button', { name: /Dialog/ }).click() + await demo.getByRole('button', { name: /Dialog/ }).click() await demo.locator('.tiny-dialog-box__wrapper').click() // 按 ESC 键,关闭 dialogBox - await page.getByRole('button', { name: /Dialog/ }).click() + await demo.getByRole('button', { name: /Dialog/ }).click() await page.locator('body').press('Escape') expect(demo.locator('.tiny-dialog-box.is-center > .tiny-dialog-box__header')).toBeHidden() }) diff --git a/examples/sites/demos/pc/app/dialog-box/form-in-dialog.spec.ts b/examples/sites/demos/pc/app/dialog-box/form-in-dialog.spec.ts index 13ede23563..0848d9c742 100644 --- a/examples/sites/demos/pc/app/dialog-box/form-in-dialog.spec.ts +++ b/examples/sites/demos/pc/app/dialog-box/form-in-dialog.spec.ts @@ -4,7 +4,7 @@ test('弹窗表单', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) await page.goto('dialog-box#form-in-dialog') const demo = page.locator('#form-in-dialog') - const dialogBox = page.locator('.tiny-dialog-box') + const dialogBox = demo.locator('.tiny-dialog-box') await page.getByRole('button', { name: '弹出表单' }).click() await expect(dialogBox.locator('.tiny-form')).toBeVisible() await demo.getByRole('textbox').first().click() @@ -17,6 +17,5 @@ test('弹窗表单', async ({ page }) => { // 验证下拉选择校验提示不会异常 await demo.locator('.tiny-select__tags-group').click() - await page.waitForTimeout(200) await expect(page.locator('.tiny-form__valid.tiny-tooltip')).not.toBeVisible() }) diff --git a/packages/renderless/src/dialog-box/vue.ts b/packages/renderless/src/dialog-box/vue.ts index 4691d64f11..d2492f2528 100644 --- a/packages/renderless/src/dialog-box/vue.ts +++ b/packages/renderless/src/dialog-box/vue.ts @@ -31,6 +31,7 @@ import { hideScrollbar, toggleFullScreen } from './index' +import { nanoid } from '@opentiny/utils' import { usePopup } from '@opentiny/vue-hooks' import type { IDialogBoxApi, @@ -83,7 +84,9 @@ const initState = ({ style: computed(() => api.computedStyle()), animationName: computed(() => api.computedAnimationName()), current, - dragStyle: null + dragStyle: null, + titleId: `tiny-dialog-box-title-${nanoid.api.nanoid(8)}`, + contentId: `tiny-dialog-box-content-${nanoid.api.nanoid(8)}` }) return state diff --git a/packages/renderless/types/dialog-box.type.ts b/packages/renderless/types/dialog-box.type.ts index 97e4721301..da59adc14a 100644 --- a/packages/renderless/types/dialog-box.type.ts +++ b/packages/renderless/types/dialog-box.type.ts @@ -61,6 +61,8 @@ export interface IDialogBoxState { rendered?: boolean mouseUpWrapperFlag: boolean mouseDownWrapperFlag: boolean + titleId: string + contentId: string } export interface IDialogBoxApi { diff --git a/packages/vue/src/dialog-box/src/pc.vue b/packages/vue/src/dialog-box/src/pc.vue index 754b024c15..bb43146c87 100644 --- a/packages/vue/src/dialog-box/src/pc.vue +++ b/packages/vue/src/dialog-box/src/pc.vue @@ -40,10 +40,14 @@ data-tag="tiny-dialog-box" :data-dialog-box-draggable="draggable" :key="state.key" + role="dialog" + :aria-modal="true" + :aria-labelledby="state.titleId" + :aria-describedby="state.contentId" >
- {{ title }} + {{ title }}
-
+