-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(components): [time-picker] fix range input without default id issue
fix time-picker type range input elements without default id value closed #16802
- Loading branch information
1 parent
c3dc4b3
commit 6c2a104
Showing
2 changed files
with
73 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/components/time-picker/src/common/range-input-id-provider.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<template> | ||
<slot | ||
:input-id-for-start="inputIdForStart" | ||
:input-id-for-end="inputIdForEnd" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { reactive, watch } from 'vue' | ||
import { pick } from 'lodash-unified' | ||
import { useFormItem, useFormItemInputId } from '@element-plus/components/form' | ||
import { timePickerDefaultProps } from './props' | ||
const props = defineProps(pick(timePickerDefaultProps, 'id')) | ||
const propForStart = reactive<{ id?: string }>({}) | ||
const propForEnd = reactive<{ id?: string }>({}) | ||
watch( | ||
() => props.id, | ||
() => { | ||
const [startInputId, endInputId] = Array.isArray(props.id) ? props.id : [] | ||
propForStart.id = startInputId | ||
propForEnd.id = endInputId | ||
}, | ||
{ immediate: true } | ||
) | ||
const { formItem } = useFormItem() | ||
const { inputId: inputIdForStart } = useFormItemInputId(propForStart, { | ||
formItemContext: formItem, | ||
}) | ||
const { inputId: inputIdForEnd } = useFormItemInputId(propForEnd, { | ||
formItemContext: formItem, | ||
}) | ||
</script> |