Skip to content
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

feat(VDatePicker): week selection #20867

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

J-Sek
Copy link
Contributor

@J-Sek J-Sek commented Jan 15, 2025

Description

  • multiple="week" let's user select week with single click
  • highlights row on hover and upon selection
  • does not include selection text format (more flexibility for developers)

Markup:

<template>
  <v-app>
    <v-container>
      <v-date-picker
        v-model="dates"
        :first-day-of-week="1"
        color="primary"
        multiple="week"
        title="Week selection"
        show-adjacent-months
        show-week
      >
        <template #header>
          <v-date-picker-header>
            {{ headerText }}
          </v-date-picker-header>
        </template>
      </v-date-picker>
      <v-btn @click="dates = []">Clear</v-btn>
      <pre>{{ dates }}</pre>
    </v-container>
  </v-app>
</template>

<script setup lang="ts">
  import { computed, ref } from 'vue'
  import { useDate } from 'vuetify'
  const dates = ref<Date[]>([])

  const adapter = useDate()

  const headerText = computed(() => {
    if (dates.value.length < 2) return 'Select week'

    const firstWeekDay = adapter.startOfWeek(dates.value[0])
    const firstYearDay = adapter.startOfYear(dates.value[0])

    const firstDayDiff = adapter.getDiff(firstWeekDay, firstYearDay, 'days')
    const weekOffset = firstYearDay.getDay() === 0 ? 1 : 0

    return `${firstWeekDay.getFullYear()} Week ${weekOffset + Math.ceil(firstDayDiff / 7)}`
  })
</script>

@J-Sek J-Sek added T: feature A new feature C: VDatePicker VDatePicker labels Jan 15, 2025
@J-Sek J-Sek self-assigned this Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VDatePicker VDatePicker T: feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant