Skip to content

Commit b531dbf

Browse files
authored
fix(VDatePickerYears): fix scroll/focus of selected year (#21951)
1 parent a97f103 commit b531dbf

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/vuetify/src/components/VDatePicker/VDatePickerYears.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import { VBtn } from '@/components/VBtn'
88
import { useDate } from '@/composables/date'
99
import { useProxiedModel } from '@/composables/proxiedModel'
1010

11+
// Directives
12+
import vIntersect from '@/directives/intersect'
13+
1114
// Utilities
12-
import { computed, nextTick, onMounted, watchEffect } from 'vue'
15+
import { computed, watchEffect } from 'vue'
1316
import { convertToUnit, createRange, genericComponent, propsFactory, templateRef, useRender } from '@/util'
1417

1518
// Types
@@ -48,6 +51,8 @@ export const VDatePickerYears = genericComponent<VDatePickerYearsSlots>()({
4851

4952
props: makeVDatePickerYearsProps(),
5053

54+
directives: { vIntersect },
55+
5156
emits: {
5257
'update:modelValue': (year: number) => true,
5358
},
@@ -91,10 +96,10 @@ export const VDatePickerYears = genericComponent<VDatePickerYearsSlots>()({
9196

9297
const yearRef = templateRef()
9398

94-
onMounted(async () => {
95-
await nextTick()
99+
function focusSelectedYear () {
96100
yearRef.el?.focus()
97-
})
101+
yearRef.el?.scrollIntoView({ block: 'center' })
102+
}
98103

99104
function isYearAllowed (year: number) {
100105
if (Array.isArray(props.allowedYears) && props.allowedYears.length) {
@@ -111,6 +116,9 @@ export const VDatePickerYears = genericComponent<VDatePickerYearsSlots>()({
111116
useRender(() => (
112117
<div
113118
class="v-date-picker-years"
119+
v-intersect={[{
120+
handler: focusSelectedYear,
121+
}, null, ['once']]}
114122
style={{
115123
height: convertToUnit(props.height),
116124
}}

0 commit comments

Comments
 (0)