mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-24 11:05:17 +08:00
fix: fix date range picker input issue (#1439)
* fix: fix date range picker input issue fix #1428 * chore: update
This commit is contained in:
parent
3313cec581
commit
1d1b74c886
@ -449,7 +449,6 @@ export default defineComponent({
|
||||
? !disabledDate(date_.toDate())
|
||||
: true
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
const formatToString = value => {
|
||||
|
@ -557,7 +557,11 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
const formatToString = value => {
|
||||
return value.map(_=> _.format(format))
|
||||
return Array.isArray(value) ? value.map(_=> _.format(format)) : value.format(format)
|
||||
}
|
||||
|
||||
const parseUserInput = value => {
|
||||
return Array.isArray(value) ? value.map(_=> dayjs(_, format)) : dayjs(value, format)
|
||||
}
|
||||
|
||||
const getDefaultValue = () => {
|
||||
@ -577,7 +581,8 @@ export default defineComponent({
|
||||
return [start, start.add(1, 'month')]
|
||||
}
|
||||
|
||||
// pickerBase.hub.emit('SetPickerOption', ['isValidValue', isValidValue])
|
||||
ctx.emit('set-picker-option', ['isValidValue', isValidValue])
|
||||
ctx.emit('set-picker-option', ['parseUserInput', parseUserInput])
|
||||
ctx.emit('set-picker-option', ['formatToString', formatToString])
|
||||
ctx.emit('set-picker-option', ['handleClear', handleClear])
|
||||
|
||||
|
@ -282,8 +282,6 @@ export default defineComponent({
|
||||
|
||||
const displayValue = computed(() => {
|
||||
if (!pickerOptions.value.panelReady) return
|
||||
if (!isTimePicker.value && valueIsEmpty.value) return
|
||||
if (!pickerVisible.value && valueIsEmpty.value) return
|
||||
const formattedValue = formatDayjsToString(parsedValue.value)
|
||||
if (Array.isArray(userInput.value)) {
|
||||
return [
|
||||
@ -293,6 +291,8 @@ export default defineComponent({
|
||||
} else if (userInput.value !== null) {
|
||||
return userInput.value
|
||||
}
|
||||
if (!isTimePicker.value && valueIsEmpty.value) return
|
||||
if (!pickerVisible.value && valueIsEmpty.value) return
|
||||
if (formattedValue) {
|
||||
return isDatesPicker.value
|
||||
? (formattedValue as Array<string>).join(', ')
|
||||
@ -359,7 +359,7 @@ export default defineComponent({
|
||||
const value = parseUserInputToDayjs(displayValue.value)
|
||||
if (value) {
|
||||
if (isValidValue(value)) {
|
||||
emitInput(value.toDate())
|
||||
emitInput(Array.isArray(value) ? value.map(_=> _.toDate()) : value.toDate())
|
||||
userInput.value = null
|
||||
}
|
||||
}
|
||||
@ -456,7 +456,7 @@ export default defineComponent({
|
||||
|
||||
const handleStartChange = () => {
|
||||
const value = parseUserInputToDayjs(userInput.value && userInput.value[0])
|
||||
if (value) {
|
||||
if (value && value.isValid()) {
|
||||
userInput.value = [formatDayjsToString(value), displayValue.value[1]]
|
||||
const newValue = [value, parsedValue.value && parsedValue.value[1]]
|
||||
if (isValidValue(newValue)) {
|
||||
@ -468,7 +468,7 @@ export default defineComponent({
|
||||
|
||||
const handleEndChange = () => {
|
||||
const value = parseUserInputToDayjs(userInput.value && userInput.value[1])
|
||||
if (value) {
|
||||
if (value && value.isValid()) {
|
||||
userInput.value = [displayValue.value[0], formatDayjsToString(value)]
|
||||
const newValue = [parsedValue.value && parsedValue.value[0], value]
|
||||
if (isValidValue(newValue)) {
|
||||
|
Loading…
Reference in New Issue
Block a user