Skip to content

feat(VDatePicker): Calculate disabled year and month #21470

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

Merged

Conversation

ikushum
Copy link
Member

@ikushum ikushum commented May 22, 2025

fixes #20465

Description

Disable month and year buttons based on allowed-dates prop when:

‼️ This is a follow up PR for #21466 and completes the second checkbox from list above. The changes in this PR are slightly computation heavy so wanted to have some discussion and see if the code is worth it.

If the allowed-dates prop is function then:

  • Code inside allowedYears will execute approx 366 * 150 = 54900 times
  • Code inside allowedMonths will execute approx 31 * 12 = 372 times

Markup:

<template>
  <v-app>
    <v-container>
        <h2>Date picker</h2>
        <v-date-picker
          mode="month"
          hide-header
          :allowed-dates="allowedDates"
        ></v-date-picker>

        <h2>Date picker years</h2>
        <VDatePickerYears
          :allowed-years="[2025, 2026]"
          class="mb-10"
        />

        <h2>Date picker months</h2>
        <VDatePickerMonths
          :allowed-months="[2, 3]"
        />
    </v-container>
  </v-app>
</template>

<script setup>
const allowedDates = value => value > new Date()
</script>

@J-Sek
Copy link
Contributor

J-Sek commented May 22, 2025

Yup. Worst case scenario is ~55k roundtrips, but also it takes < 300ms (with console log commented out), so it basically depends on complexity of that function... in addition to the devs being careless by forgetting to put min and max

<template>
  <h2>Select winter holiday with the most epic party</h2>
  <v-date-picker :allowed-dates="allowedDates" mode="month" hide-header />
</template>

<script setup lang="ts">
  const allowedDates = (v: Date) => {
    // console.count('allowedDates') // over 54500
    return v.getMonth() === 11 && v.getDate() > 21
  }
</script>

@ikushum ikushum merged commit b7ec7fa into feat/disable-year-and-month May 22, 2025
19 checks passed
@ikushum ikushum deleted the feat/disable-year-and-month-function branch May 22, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants