mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-21 01:02:59 +08:00
fix(components): [calendar] improve range validation (#18125)
* fix(components): [calendar] improve range validation * fix: update
This commit is contained in:
parent
29a21e86ba
commit
50e02f3ab9
@ -1,7 +1,7 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import dayjs from 'dayjs'
|
||||
import { useLocale } from '@element-plus/hooks'
|
||||
import { debugWarn } from '@element-plus/utils'
|
||||
import { debugWarn, isArray, isDate } from '@element-plus/utils'
|
||||
import { INPUT_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants'
|
||||
|
||||
import type { ComputedRef, SetupContext } from 'vue'
|
||||
@ -78,7 +78,13 @@ export const useCalendar = (
|
||||
|
||||
// if range is valid, we get a two-digit array
|
||||
const validatedRange = computed(() => {
|
||||
if (!props.range) return []
|
||||
if (
|
||||
!props.range ||
|
||||
!isArray(props.range) ||
|
||||
props.range.length !== 2 ||
|
||||
props.range.some((item) => !isDate(item))
|
||||
)
|
||||
return []
|
||||
const rangeArrDayjs = props.range.map((_) => dayjs(_).locale(lang.value))
|
||||
const [startDayjs, endDayjs] = rangeArrDayjs
|
||||
if (startDayjs.isAfter(endDayjs)) {
|
||||
|
Loading…
Reference in New Issue
Block a user