Skip to content

feat(VDatePicker): re-introduce first-day-of-year prop #21760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

J-Sek
Copy link
Contributor

@J-Sek J-Sek commented Jul 14, 2025

Description

  • re-introduces first-day-of-year from v2 (without locale-* prefix)
  • users won't be forced to use a specific locale when they want the week numbers to align with the target audience
    • e.g. I will be able to have en messages, and won't be forced to either en-GB or en-US for week-related configuration

Note: ⚠️ This first-day-of-year is working fine only when combined with first-day-of-week="1".


  • make it work with first-day-of-week
  • refactoring
  • unit tests
  • week-min-size prop as a recommended alternative

resolves #20270

Playground
<template>
  <v-app theme="dark">
    <v-container max-width="800">
      <div class="d-flex flex-wrap ga-3 justify-space-between">
        <v-locale-provider locale="de">
          <!-- both pickers should show the same week values when firstDayOfYear is defined -->
          <v-date-picker
            :first-day-of-week="firstDayOfWeek"
            :first-day-of-year="firstDayOfYear"
            :model-value="`${year}-01-01`"
            elevation="4"
            title="with custom locale (de)"
            show-adjacent-months
            show-week
          />
        </v-locale-provider>

        <v-date-picker
          :first-day-of-week="firstDayOfWeek"
          :first-day-of-year="firstDayOfYear"
          :model-value="`${year}-01-01`"
          elevation="4"
          title="with default locale (en)"
          show-adjacent-months
          show-week
        />
      </div>
      <br>

      <v-number-input v-model="year" :max="2040" :min="2000" control-variant="split" />

      <div class="d-flex ga-3 align-center">
        <v-switch v-model="customFirstDayOfWeek" label="custom" hide-details />
        <v-slider
          v-if="customFirstDayOfWeek"
          v-model="firstDayOfWeek"
          :step="1"
          :ticks="'SMTWTFS'.split('').reduce((o,v,i) => ({ ...o, [i]: v}), {})"
          label="first day of week"
          max="6"
          min="0"
          show-ticks="always"
          hide-details
        />

      </div>

      <div class="d-flex ga-3 align-center">
        <v-switch v-model="customFirstDayOfYear" label="custom" hide-details />
        <v-slider
          v-if="customFirstDayOfYear"
          v-model="firstDayOfYear"
          :step="1"
          :ticks="'SMTWTFS'.split('').reduce((o,v,i) => ({ ...o, [i]: v}), {})"
          label="first day of year"
          max="6"
          min="0"
          show-ticks="always"
          hide-details
        />
      </div>
    </v-container>
  </v-app>
</template>

<script setup lang="ts">
  import { computed, onBeforeMount, shallowRef } from 'vue'
  import { useDate } from 'vuetify'

  const year = shallowRef(2032)

  const firstDayOfWeek = shallowRef<number | undefined>(0)

  const customFirstDayOfWeek = computed<boolean>({
    get: () => firstDayOfWeek.value !== undefined,
    set: v => firstDayOfWeek.value = v ? 0 : undefined,
  })

  const firstDayOfYear = shallowRef<number | undefined>()

  const customFirstDayOfYear = computed<boolean>({
    get: () => firstDayOfYear.value !== undefined,
    set: v => firstDayOfYear.value = v ? 0 : undefined,
  })

  const adapter = useDate()
  onBeforeMount(() => {
    adapter.locale = { en: 'en-GB' }
  })
</script>

@J-Sek J-Sek self-assigned this Jul 14, 2025
@J-Sek J-Sek changed the base branch from master to dev July 14, 2025 15:19
@J-Sek J-Sek force-pushed the feat/vdatepicker-first-day-of-year branch 2 times, most recently from d70cb12 to b422e09 Compare July 14, 2025 15:30
@J-Sek J-Sek changed the base branch from dev to master July 23, 2025 08:56
@J-Sek J-Sek force-pushed the feat/vdatepicker-first-day-of-year branch 2 times, most recently from da36daa to 3e33a5a Compare July 23, 2025 09:14
@J-Sek J-Sek marked this pull request as draft July 23, 2025 09:15
@J-Sek J-Sek force-pushed the feat/vdatepicker-first-day-of-year branch from 3e33a5a to fe7b5f3 Compare July 24, 2025 22:15
@J-Sek J-Sek force-pushed the feat/vdatepicker-first-day-of-year branch from fe7b5f3 to 8f0b2c8 Compare July 24, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report][3.6.14] VDatePicker locale-first-day-of-year missing in Vuetify 3
1 participant