Skip to content

Commit f26a376

Browse files
committed
feat(datepicker): Determine which cell is tabbable initially
1 parent 8e02f3b commit f26a376

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/components/Datepicker.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<slot name="beforeCalendarHeader" />
6565
<Component
6666
:is="picker"
67+
ref="picker"
6768
:bootstrap-styling="bootstrapStyling"
6869
class="picker-view"
6970
:day-cell-content="dayCellContent"
@@ -112,6 +113,7 @@ import DateInput from '~/components/DateInput.vue'
112113
import DisabledDate from '~/utils/DisabledDate'
113114
import inputProps from '~/mixins/inputProps.vue'
114115
import makeDateUtils from '~/utils/DateUtils'
116+
import navMixin from '~/mixins/navMixin.vue'
115117
import PickerDay from '~/components/PickerDay.vue'
116118
import PickerMonth from '~/components/PickerMonth.vue'
117119
import PickerYear from '~/components/PickerYear.vue'
@@ -126,7 +128,7 @@ export default {
126128
PickerYear,
127129
Popup,
128130
},
129-
mixins: [inputProps],
131+
mixins: [inputProps, navMixin],
130132
props: {
131133
appendToBody: {
132134
type: Boolean,
@@ -438,6 +440,10 @@ export default {
438440
}
439441
440442
this.setInitialView()
443+
this.$nextTick(() => {
444+
this.setTabbableCell()
445+
})
446+
441447
this.$emit('opened')
442448
},
443449
/**

src/mixins/navMixin.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script>
2+
export default {
3+
data() {
4+
return {
5+
tabbableCell: null,
6+
}
7+
},
8+
methods: {
9+
/**
10+
* Sets the focus-trapped cell in the picker
11+
*/
12+
// eslint-disable-next-line complexity
13+
setTabbableCell() {
14+
if (!this.$refs.picker || !this.$refs.picker.$refs.cells) {
15+
return
16+
}
17+
18+
const pickerCells = this.$refs.picker.$refs.cells.$el
19+
20+
this.tabbableCell =
21+
pickerCells.querySelector('button.selected:not(.muted):enabled') ||
22+
pickerCells.querySelector('button.open:not(.muted):enabled') ||
23+
pickerCells.querySelector('button.today:not(.muted):enabled') ||
24+
pickerCells.querySelector('button.cell:not(.muted):enabled')
25+
},
26+
},
27+
}
28+
</script>

0 commit comments

Comments
 (0)