feat: enhance month availability checks in SingleDatePicker component
This commit is contained in:
parent
13a55d7eda
commit
84e8f62ec3
|
@ -115,7 +115,13 @@
|
||||||
if (currentYear.value < 100) currentYear.value = parseInt(`20${currentYear.value}`)
|
if (currentYear.value < 100) currentYear.value = parseInt(`20${currentYear.value}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function monthNotAvailable() {
|
function monthNotAvailable(month: number): boolean {
|
||||||
|
// When the last day of a month not inside the range of available dates
|
||||||
|
const lastDayOfMonth = new Date(currentYear.value, month + 1, 0)
|
||||||
|
if (availableRangeStart.value && lastDayOfMonth < availableRangeStart.value) return true
|
||||||
|
// When the first day of a month not inside the range of available dates
|
||||||
|
const firstDayOfMonth = new Date(currentYear.value, month, 1)
|
||||||
|
if (availableRangeEnd.value && firstDayOfMonth > availableRangeEnd.value) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,15 +191,15 @@
|
||||||
<div class='__datenel_month-selector-body'>
|
<div class='__datenel_month-selector-body'>
|
||||||
<button
|
<button
|
||||||
v-for="(_, index) in 12"
|
v-for="(_, index) in 12"
|
||||||
:class="`__datenel_item ${monthNotAvailable() && '__datenel_not-available'}`"
|
:class="`__datenel_item ${monthNotAvailable(index) && '__datenel_not-available'} ${currentMonth === index && '__datenel_active'}`"
|
||||||
key={index}
|
key={index}
|
||||||
@click="() => {
|
@click="() => {
|
||||||
currentMonth = index
|
currentMonth = index
|
||||||
selectMonth = false
|
selectMonth = false
|
||||||
}"
|
}"
|
||||||
:aria-label="`Go to ${new Date(currentYear, index).toLocaleString(localization, { month: 'long' })} of the year ${currentYear}`"
|
:aria-label="`Go to ${new Date(currentYear, index).toLocaleString(localization, { month: 'long' })} of the year ${currentYear}`"
|
||||||
:disabled="monthNotAvailable()"
|
:disabled="monthNotAvailable(index)"
|
||||||
:aria-hidden="monthNotAvailable()"
|
:aria-hidden="monthNotAvailable(index)"
|
||||||
>
|
>
|
||||||
{{new Date(currentYear, index).toLocaleString(localization, { month: 'long' })}}
|
{{new Date(currentYear, index).toLocaleString(localization, { month: 'long' })}}
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user