Skip to content

Commit

Permalink
Merge pull request #773 from nathanreyes/bug/range-input-switching
Browse files Browse the repository at this point in the history
Fix range input switching and page adjustments when date range is null
  • Loading branch information
Nathan Reyes authored Jan 30, 2021
2 parents 7263aa3 + 4f34135 commit 1791424
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
32 changes: 32 additions & 0 deletions docs/.vuepress/components/github/769.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<v-date-picker v-model="range" is-range>
<template v-slot="{ inputValue, inputEvents }">
<div class="flex">
<input
:class="inputClass"
:value="inputValue.start"
v-on="inputEvents.start"
/>
<span class="mx-2 text-lg">&rarr;</span>
<input
:class="inputClass"
:value="inputValue.end"
v-on="inputEvents.end"
/>
</div>
</template>
</v-date-picker>
</template>

<script>
export default {
githubTitle:
'Range datepicker with double inputs disallows typing dates manually',
data() {
return {
range: null,
inputClass: 'px-2 py-1 border rounded',
};
},
};
</script>
3 changes: 2 additions & 1 deletion docs/changelog/v2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,5 @@ Fixes single use of `highlight.contentStyle` or `highlight.contentClass`

### Bug Fixes

* Fix `on-bottom` class when `trim-weeks` prop is used
* Fix `on-bottom` class when `trim-weeks` prop is used
* Fix date range clearing and page adjustment when end date is missing
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v-calendar",
"version": "2.2.2",
"version": "2.2.3",
"private": false,
"description": "A clean and extendable plugin for building simple attributed calendars in Vue.js.",
"author": "Nathan Reyes <[email protected]>",
Expand Down
22 changes: 16 additions & 6 deletions src/components/DatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,10 @@ export default {
let inputValue = e.target.value;
this.inputValues.splice(isStart ? 0 : 1, 1, inputValue);
if (this.isRange) {
inputValue = { start: this.inputValues[0], end: this.inputValues[1] };
inputValue = {
start: this.inputValues[0],
end: this.inputValues[1] || this.inputValues[0],
};
}
this.updateValue(inputValue, {
config,
Expand All @@ -501,7 +504,10 @@ export default {
const inputValue = e.target.value;
this.inputValues.splice(isStart ? 0 : 1, 1, inputValue);
const value = this.isRange
? { start: this.inputValues[0], end: this.inputValues[1] }
? {
start: this.inputValues[0],
end: this.inputValues[1] || this.inputValues[0],
}
: inputValue;
this.updateValue(value, {
config,
Expand Down Expand Up @@ -570,10 +576,7 @@ export default {
}
// 2. Validation (date or range)
const isDisabled =
this.hasValue(normalizedValue) &&
this.disabledAttribute &&
this.disabledAttribute.intersectsDate(normalizedValue);
const isDisabled = this.valueIsDisabled(normalizedValue);
if (isDisabled) {
if (isDragging) return;
normalizedValue = this.value_;
Expand Down Expand Up @@ -696,6 +699,13 @@ export default {
}
return datesAreEqual(a, b);
},
valueIsDisabled(value) {
return (
this.hasValue(value) &&
this.disabledAttribute &&
this.disabledAttribute.intersectsDate(value)
);
},
formatInput() {
this.$nextTick(() => {
const opts = {
Expand Down

0 comments on commit 1791424

Please sign in to comment.