File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
- <div class =" vdp-datepicker" :class =" [wrapperClass, { rtl: isRtl }]" >
2
+ <div
3
+ class =" vdp-datepicker"
4
+ :class =" [wrapperClass, { rtl: isRtl }]"
5
+ @keydown.tab =" tabThroughNavigation($event)"
6
+ >
3
7
<DateInput
4
8
:id =" id"
5
9
ref =" dateInput"
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ export default {
4
4
return {
5
5
navElements: [],
6
6
tabbableCell: null ,
7
+ navElementsFocusedIndex: 0 ,
7
8
}
8
9
},
9
10
methods: {
@@ -111,6 +112,47 @@ export default {
111
112
pickerCells .querySelector (' button.today:not(.muted):enabled' ) ||
112
113
pickerCells .querySelector (' button.cell:not(.muted):enabled' )
113
114
},
115
+ /**
116
+ * Tab backwards through the focus-trapped elements
117
+ */
118
+ tabBackwards () {
119
+ this .navElementsFocusedIndex -= 1
120
+
121
+ if (this .navElementsFocusedIndex < 0 ) {
122
+ this .navElementsFocusedIndex = this .navElements .length - 1
123
+ }
124
+
125
+ this .navElements [this .navElementsFocusedIndex ].focus ()
126
+ },
127
+ /**
128
+ * Tab forwards through the focus-trapped elements
129
+ */
130
+ tabForwards () {
131
+ this .navElementsFocusedIndex += 1
132
+
133
+ if (this .navElementsFocusedIndex >= this .navElements .length ) {
134
+ this .navElementsFocusedIndex = 0
135
+ }
136
+
137
+ this .navElements [this .navElementsFocusedIndex ].focus ()
138
+ },
139
+ /**
140
+ * Tab through the focus-trapped elements
141
+ * @param event
142
+ */
143
+ tabThroughNavigation (event ) {
144
+ // Allow normal tabbing when closed
145
+ if (! this .isOpen ) {
146
+ return
147
+ }
148
+ event .preventDefault ()
149
+
150
+ if (event .shiftKey ) {
151
+ this .tabBackwards ()
152
+ } else {
153
+ this .tabForwards ()
154
+ }
155
+ },
114
156
},
115
157
}
116
158
</script >
You can’t perform that action at this time.
0 commit comments