From a055907b0d723cc902935fd3c37ef290b1b62d15 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 18 Nov 2021 10:10:00 +0800 Subject: [PATCH] feat(DropdownMenu): add role, aria and tabindex for a11y (#9893) --- .../vant/src/dropdown-item/DropdownItem.tsx | 10 +- .../vant/src/dropdown-menu/DropdownMenu.tsx | 5 +- .../test/__snapshots__/demo.spec.ts.snap | 30 ++-- .../test/__snapshots__/index.spec.tsx.snap | 149 +++++++++++------- packages/vant/src/dropdown-menu/types.ts | 1 + 5 files changed, 128 insertions(+), 67 deletions(-) diff --git a/packages/vant/src/dropdown-item/DropdownItem.tsx b/packages/vant/src/dropdown-item/DropdownItem.tsx index 58efef1d2..fd210535c 100644 --- a/packages/vant/src/dropdown-item/DropdownItem.tsx +++ b/packages/vant/src/dropdown-item/DropdownItem.tsx @@ -58,7 +58,7 @@ export default defineComponent({ showWrapper: false, }); - const { parent } = useParent(DROPDOWN_KEY); + const { parent, index } = useParent(DROPDOWN_KEY); if (!parent) { if (process.env.NODE_ENV !== 'production') { @@ -142,14 +142,16 @@ export default defineComponent({ return ( + /> ); }; @@ -175,12 +177,14 @@ export default defineComponent({ > (); const barRef = ref(); const offset = ref(0); @@ -115,6 +117,7 @@ export default defineComponent({ return (
-
@@ -14,7 +15,8 @@ exports[`should render demo and match snapshot 1`] = `
-
@@ -46,7 +48,8 @@ exports[`should render demo and match snapshot 1`] = `
-
@@ -56,7 +59,8 @@ exports[`should render demo and match snapshot 1`] = `
-
@@ -88,7 +92,8 @@ exports[`should render demo and match snapshot 1`] = `
-
@@ -98,7 +103,8 @@ exports[`should render demo and match snapshot 1`] = `
-
@@ -130,7 +136,8 @@ exports[`should render demo and match snapshot 1`] = `
-
@@ -140,7 +147,8 @@ exports[`should render demo and match snapshot 1`] = `
-
@@ -172,7 +180,8 @@ exports[`should render demo and match snapshot 1`] = `
-
@@ -181,7 +190,8 @@ exports[`should render demo and match snapshot 1`] = `
-
diff --git a/packages/vant/src/dropdown-menu/test/__snapshots__/index.spec.tsx.snap b/packages/vant/src/dropdown-menu/test/__snapshots__/index.spec.tsx.snap index 378b4696c..44c7a79d5 100644 --- a/packages/vant/src/dropdown-menu/test/__snapshots__/index.spec.tsx.snap +++ b/packages/vant/src/dropdown-menu/test/__snapshots__/index.spec.tsx.snap @@ -3,7 +3,8 @@ exports[`click option 1`] = `
-
@@ -13,7 +14,8 @@ exports[`click option 1`] = `
-
@@ -36,9 +38,11 @@ exports[`click option 1`] = `