mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* chore: [select] remove @ts-nocheck directive * Update packages/components/select/src/option.vue Co-authored-by: qiang <qw13131wang@gmail.com> * chore: delete useless type * Update packages/components/select/src/useSelect.ts Co-authored-by: qiang <qw13131wang@gmail.com> * fix: type error * fix: type error * chore: use buildProps * chore: add type * Update packages/components/select/src/useSelect.ts Co-authored-by: btea <2356281422@qq.com> * chore: fix type * chore: fix type * chore: fix types --------- Co-authored-by: warmthsea <2586244885@qq.com> Co-authored-by: sea <45450994+warmthsea@users.noreply.github.com> Co-authored-by: qiang <qw13131wang@gmail.com> Co-authored-by: btea <2356281422@qq.com>
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { defineComponent, inject, watch } from 'vue'
|
|
import { selectKey } from '@element-plus/components/select'
|
|
import { isClient } from '@element-plus/utils'
|
|
import type { SelectContext } from '@element-plus/components/select'
|
|
import type { PropType } from 'vue'
|
|
|
|
// same as el-option instance,
|
|
// these are required for `cachedOptions`
|
|
export type CacheOption = {
|
|
value: string | number | boolean | object
|
|
currentLabel: string | number
|
|
isDisabled: boolean
|
|
}
|
|
|
|
export default defineComponent({
|
|
props: {
|
|
data: {
|
|
type: Array as PropType<CacheOption[]>,
|
|
default: () => [],
|
|
},
|
|
},
|
|
setup(props) {
|
|
const select = inject(selectKey) as NonNullable<SelectContext>
|
|
|
|
watch(
|
|
() => props.data,
|
|
() => {
|
|
props.data.forEach((item) => {
|
|
if (!select.states.cachedOptions.has(item.value)) {
|
|
// TODO: the type of 'item' is not compatible with the type of 'cachedOptions',
|
|
// which may indicate potential runtime issues.
|
|
// @ts-expect-error
|
|
select.states.cachedOptions.set(item.value, item)
|
|
}
|
|
})
|
|
|
|
// fork from packages/select/src/useSelect.ts#330
|
|
const inputs = select.selectRef?.querySelectorAll('input') || []
|
|
if (
|
|
isClient &&
|
|
!Array.from(inputs).includes(
|
|
document.activeElement as HTMLInputElement
|
|
)
|
|
) {
|
|
select.setSelected()
|
|
}
|
|
},
|
|
{ flush: 'post', immediate: true }
|
|
)
|
|
|
|
return () => undefined
|
|
},
|
|
})
|