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): pass through slots for day, week, month to sub components #21121

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

Conversation

luukvnes
Copy link

Description

This change adds a new dateClass prop to the VDatePicker and VDateInput components, allowing for custom styling of individual dates in the calendar.
The dateClass prop takes a function that takes a date and returns an array of classes. These classes are added to the dates in the calender.

My particular usecase is that i want to add a red border around particular days to signify an error happening on that day. Currently the easiest way is to use document.queryselector, this is particularly a nuisance, because you have to reapply the styling anytime the component switches to the view with single dates (not months/years).

Markup:

<template>
  <v-app>
    <v-container>
      <v-date-picker :date-class="d => d.getDay() % 2 == 0 ? ['custom-class'] : []" />
      <v-date-input :date-class="d => d.getDay() % 2 == 0 ? ['custom-class'] : []" />
    </v-container>
  </v-app>
</template>
<script>
  export default {
    name: 'Playground',
    setup () {
      return {
        //
      }
    },
  }
</script>

<style>
  .custom-class button {
    border: 1px red solid;
  }
</style>

@KaelWD
Copy link
Member

KaelWD commented Mar 18, 2025

There's already a slot for this:

<template #day="{ item, props }">
  <v-btn
    v-bind="props"
    :class="{ 'custom-class': item.date.getDay() % 2 == 0 }"
  />
</template>

@KaelWD KaelWD closed this Mar 18, 2025
@luukvnes
Copy link
Author

@KaelWD Ah, i missed that. Currently though the VDatePicker does not pass slots through to the VDatePickerMonth. Would a pull request including a change like the following (where slots are passed through) be accepted? luukvnes@d09c303#diff-e52a094feb57d0b046a8b9c49e5b4870078f419377cccff97ad7bac766cd09ab

Obviously this is missing type declarations and documentions, but as an idea

@KaelWD
Copy link
Member

KaelWD commented Mar 18, 2025

Ok yeah that should definitely be forwarded.

@KaelWD KaelWD reopened this Mar 18, 2025
@luukvnes
Copy link
Author

<template>
  <v-app>
    <v-container>
      <v-date-picker>
        <template #day="{ item, props }">
          <v-btn
            v-bind="props"
            :class="{ 'custom-class': item.date.getDay() % 2 == 0 }"
          />
        </template>
        <template #month="{ month, props }">
          <v-btn
            v-bind="props"
            :class="{ 'custom-class': month.text == 'Jan' }"
          >
            {{ month.text }}
          </v-btn>
        </template>
        <template #year="{ year, props }">
          <v-btn
            v-bind="props"
            :class="{ 'custom-class': year.text == '2022' }"
          />
        </template>
      </v-date-picker>
    </v-container>
  </v-app>
</template>
<script>
  export default {
    name: 'Playground',
    setup () {
      return {
        //
      }
    },
  }
</script>

<style>
  .custom-class {
    border: 1px red solid;
  }
</style>

@luukvnes luukvnes changed the title feat(VDatePickerMonth): add prop for adding css classes to specific date feat(VDatePicker): pass through slots for day, week, month to sub components Mar 18, 2025
@luukvnes
Copy link
Author

Description
This change passes through the slots for VDatePicker sub components, allowing for custom styling of individual dates in the calendar.
The dateClass prop takes a function that takes a date and returns an array of classes. These classes are added to the dates in the calender.

@luukvnes luukvnes force-pushed the feat/v3-custom-class-date-picker-dates branch from cb06ca9 to 83c0d3a Compare March 19, 2025 14:49
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.

3 participants