Year Picker
Choose one year from a compact paged year grid.
Usage
Graduation year
Choose one graduation year from a paged year grid.
Choose one graduation year from a paged year grid.
<!-- Year Picker / Graduation Year -->
<script setup lang="ts">
import { YearPickerRoot, YearPickerAnchor, YearPickerInput, YearPickerTrigger, YearPickerContent, YearPickerPreviousPage, YearPickerNextPage, YearPickerGrid, YearPickerCell } from '@sectile/vue/year-picker'
import { CalendarDays } from '@lucide/vue'
const graduationYear = { year: 2028, month: 1, day: 1 }
</script>
<template>
<YearPickerRoot :default-value="graduationYear" v-slot="{ years }">
<YearPickerAnchor>
<YearPickerInput aria-label="Graduation year" />
<YearPickerTrigger class="catalog-picker-trigger" aria-label="Open year picker">
<CalendarDays :size="18" aria-hidden="true" />
</YearPickerTrigger>
</YearPickerAnchor>
<YearPickerContent>
<YearPickerPreviousPage aria-label="Previous years">‹</YearPickerPreviousPage>
<strong>{{ years.flat()[0].year }}–{{ years.flat().at(-1).year }}</strong>
<YearPickerNextPage aria-label="Next years">›</YearPickerNextPage>
<YearPickerGrid>
<YearPickerCell v-for="year in years.flat()" :key="year.year" :value="year">
{{ year.year }}
</YearPickerCell>
</YearPickerGrid>
</YearPickerContent>
</YearPickerRoot>
</template>Planning window
Choose a planning year from the active page of years.
Choose a planning year from the active page of years.
<!-- Year Picker / Planning Window -->
<script setup lang="ts">
import { YearPickerRoot, YearPickerAnchor, YearPickerInput, YearPickerTrigger, YearPickerContent, YearPickerPreviousPage, YearPickerNextPage, YearPickerGrid, YearPickerCell } from '@sectile/vue/year-picker'
import { CalendarDays } from '@lucide/vue'
const graduationYear = { year: 2028, month: 1, day: 1 }
</script>
<template>
<YearPickerRoot :default-value="graduationYear" v-slot="{ years }">
<YearPickerAnchor>
<YearPickerInput aria-label="Graduation year" />
<YearPickerTrigger class="catalog-picker-trigger" aria-label="Open year picker">
<CalendarDays :size="18" aria-hidden="true" />
</YearPickerTrigger>
</YearPickerAnchor>
<YearPickerContent>
<YearPickerPreviousPage aria-label="Previous years">‹</YearPickerPreviousPage>
<strong>{{ years.flat()[0].year }}–{{ years.flat().at(-1).year }}</strong>
<YearPickerNextPage aria-label="Next years">›</YearPickerNextPage>
<YearPickerGrid>
<YearPickerCell v-for="year in years.flat()" :key="year.year" :value="year">
{{ year.year }}
</YearPickerCell>
</YearPickerGrid>
</YearPickerContent>
</YearPickerRoot>
</template>Controlled
Let the parent own the current value and apply accepted changes back to the component.
Let the parent own the current value and apply accepted changes back to the component.
<!-- Year Picker / Controlled -->
<script setup lang="ts">
import { ref } from 'vue'
import { YearPickerRoot, YearPickerAnchor, YearPickerInput, YearPickerTrigger, YearPickerContent, YearPickerPreviousPage, YearPickerNextPage, YearPickerGrid, YearPickerCell } from '@sectile/vue/year-picker'
import { CalendarDays } from '@lucide/vue'
const graduationYear = { year: 2028, month: 1, day: 1 }
const value = ref(graduationYear)
</script>
<template>
<YearPickerRoot v-model="value" v-slot="{ years }">
<YearPickerAnchor>
<YearPickerInput aria-label="Graduation year" />
<YearPickerTrigger class="catalog-picker-trigger" aria-label="Open year picker">
<CalendarDays :size="18" aria-hidden="true" />
</YearPickerTrigger>
</YearPickerAnchor>
<YearPickerContent>
<YearPickerPreviousPage aria-label="Previous years">‹</YearPickerPreviousPage>
<strong>{{ years.flat()[0].year }}–{{ years.flat().at(-1).year }}</strong>
<YearPickerNextPage aria-label="Next years">›</YearPickerNextPage>
<YearPickerGrid>
<YearPickerCell v-for="year in years.flat()" :key="year.year" :value="year">
{{ year.year }}
</YearPickerCell>
</YearPickerGrid>
</YearPickerContent>
</YearPickerRoot>
</template>Floating positioning
This component uses the shared positioning engine. Use the live positioning example to change side, align, offsets, collision boundaries, strategy, and tracking while inspecting the resolved placement.
API
Vue package: @sectile/vue/temporal/year-picker
YearPickerRootYearPickerTriggerYearPickerAnchorYearPickerPortalYearPickerContentYearPickerGridYearPickerCellYearPickerInputYearPickerPreviousPageYearPickerNextPage
Props
YearPickerRootProps
alignAlignment of positioned content relative to its anchor.
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
avoidCollisionsWhether positioned content may flip or shift to remain visible.
collisionBoundaryBoundary used to keep positioned content visible.
collisionPaddingSpace kept between positioned content and its collision boundary.
defaultHighlightedValueInitially highlighted value for uncontrolled state.
defaultOpenInitial uncontrolled open state.
defaultValueInitial value used when the component owns its state.
defaultViewInitial calendar or picker view.
disabledWhether interaction is unavailable.
hideWhenDetachedWhether positioned content hides when its anchor leaves the layout.
highlightedValueValue currently highlighted for keyboard interaction.
labelAccessible name announced for the control.
modelValueCurrent value when state is controlled by the parent.
openWhether the associated popup or disclosure is open.
policiesBehavior policies that customize validation, movement, or selection.
positionWhether the popup is positioned relative to its trigger.
readonlyWhether the value can be inspected but not changed.
referenceDateDeterministic civil date used when a calendar has no selected or highlighted value.
requiredWhether the control must contain a valid value before submission.
sidePreferred side of the anchor for positioned content.
sideOffsetDistance between positioned content and its anchor.
strategyCSS positioning strategy used for anchored content.
trackingUpdate strategy used while anchored content is open.
YearPickerPartProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
YearPickerPortalProps
deferWhether Teleport target resolution waits until the end of the current mount or update tick.
disabledWhether interaction is unavailable.
toTeleport target for portalled content.
Slots
YearPickerRootSlotProps
datesDates projected by the active view.
disabledWhether interaction is unavailable.
highlightedValueValue currently highlighted for interaction.
monthsMonths projected by the active view.
openWhether the associated popup or disclosure is open.
readonlyWhether the value can be inspected but not changed.
valueCurrent value exposed by this contract.
viewCurrent calendar anchor.
viewModeActive calendar view mode.
yearsYears projected by the active view.
YearPickerCellSlotProps
currentWhether this item represents the current position.
disabledWhether interaction is unavailable.
highlightedWhether this item is highlighted for interaction.
inRangeWhether this value lies inside the selected range.
selectedWhether this item is selected.
valueCurrent value exposed by this contract.
Other types
YearPickerValueChangeHandler
type YearPickerValueChangeHandler = NonNullable<InstanceType<typeof YearPickerRoot>['$props']['onUpdate:modelValue']>YearPickerOpenChangeHandler
type YearPickerOpenChangeHandler = NonNullable<InstanceType<typeof YearPickerRoot>['$props']['onUpdate:open']>YearPickerHighlightedValueChangeHandler
type YearPickerHighlightedValueChangeHandler = NonNullable<InstanceType<typeof YearPickerRoot>['$props']['onUpdate:highlightedValue']>YearPickerValue
| Name | Type | Required |
|---|---|---|
year | number | Yes |
month | number | Yes |
day | number | Yes |
Parts
Shared scope: [data-scope="year-picker"]. Combine it with a part selector to keep styles local to this component.
| Part | Selector | Role | Extra attributes |
|---|---|---|---|
input | [data-part="input"] | Accepts the editable value or draft. | — |
anchor | [data-part="anchor"] | Provides the positioning reference for floating content. | — |
trigger | [data-part="trigger"] | Opens, closes, or activates the associated content. | — |
content | [data-part="content"] | Contains the component content shown for the active state. | — |
grid | [data-part="grid"] | Groups cells into a navigable two-dimensional structure. | — |
cell | [data-part="cell"] | Represents one navigable or selectable grid value. | — |
previous-page | [data-part="previous-page"] | Moves to the previous page. | — |
next-page | [data-part="next-page"] | Moves to the next page. | — |
Keyboard interaction
| Key | Behavior |
|---|---|
| Arrow keys | Move between years in the active page. |
| Page Up / Page Down | Move to the previous or next page of years. |
| Enter / Space | Select the highlighted year. |
| Escape | Close the year grid without changing the value. |
Accessibility
The labeled input and trigger own a paged year grid with selected, highlighted, and disabled cells.
