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

[Bug Report][3.6.8] v-date-input multiple="range" doesn't respond to text input #19951

Open
tjhiggins opened this issue Jun 5, 2024 · 1 comment

Comments

@tjhiggins
Copy link

tjhiggins commented Jun 5, 2024

Environment

Vuetify Version: 3.6.8
Vue Version: 3.4.27
Browsers: Chrome 125.0.0.0
OS: Windows 10

Steps to reproduce

Issue 1: Doesn't respond to text input

  1. Click on the input's text-field
  2. Edit the text in the input to be a different day/month/year than the current selection ex. 01/05/2023 - 02/05/2023
  3. Note that this doesn't change the selected dates and the input text won't match the selection

Issue 2: Hitting enter in the input's text-field clears the selection

  1. Click on the input's text-field
  2. Hit enter
  3. Note that the selection is cleared and the v-model is now an invalid date

Expected Behavior

  1. Changing the input text - updates the selected dates in the range
  2. Hitting enter doesn't alter the selected dates

Actual Behavior

  1. Changing the input text - does nothing
  2. Hitting enter - clears the selection and makes it an invalid date

Reproduction Link

https://play.vuetifyjs.com/#...

@tjhiggins
Copy link
Author

Until these two issues are fixed. Here are the workarounds I'm using for anyone else who hits. Using date-fns for the date adapter.

<script setup lang="ts">
const date = useDate();
const selectedDates = ref([]);

// Vuetify bug where changing text input doesn't update selected dates
// https://github.com/vuetifyjs/vuetify/issues/19951
function onInput(event: InputEvent) {
  const input = event.target as HTMLInputElement;

  const [start, end] = input.value.split(' - ').map((d) => date.parse(d, 'P'));
  if (start && date.isValid(start) && end && date.isValid(end)) {
    selectedDates.value = date.eachDayOfInterval({ start, end });
  }
}

// Vuetify bug hitting enter inside of date-input multiple="range"
// https://github.com/vuetifyjs/vuetify/issues/19951
let lastSelectedDates = [new Date()];
watch(selectedDates, () => {
  if (!Array.isArray(selectedDates.value)) {
    selectedDates.value = lastSelectedDates;
  }
  lastSelectedDates = selectedDates.value;
});
</script>

<template>
  <v-date-input
    v-model="selectedDates"
    @input="onInput"
  >
  </v-date-input>
</template>

RafalOsieka added a commit to RafalOsieka/vuetify-date-input that referenced this issue Jun 5, 2024
Refactored date adapter to make the Intl format options available for custom functions

resolves vuetifyjs#19803
resolved vuetifyjs#19951
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant