Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/vuetify/src/components/VDatePicker/VDatePickerYears.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,18 @@ export const VDatePickerYears = genericComponent<VDatePickerYearsSlots>()({
model.value = model.value ?? adapter.getYear(adapter.date())
})

const containerRef = templateRef()
const yearRef = templateRef()

function focusSelectedYear () {
yearRef.el?.scrollIntoView({ block: 'center' })
const container = containerRef.el
const target = yearRef.el
if (!container || !target) return

const containerRect = container.getBoundingClientRect()
const targetRect = target.getBoundingClientRect()

container.scrollTop += (targetRect.top - containerRect.top) - (container.clientHeight / 2) + (targetRect.height / 2)
}

function isYearAllowed (year: number) {
Expand All @@ -116,6 +124,7 @@ export const VDatePickerYears = genericComponent<VDatePickerYearsSlots>()({
useRender(() => (
<div
class="v-date-picker-years"
ref={ containerRef }
v-intersect={[{
handler: focusSelectedYear,
}, null, ['once']]}
Expand Down