Files
element-plus/packages/components/tree-select/src/cache-options.ts
kooriookami 5844947198 refactor(components): [select & select-v2] Refactor components (#15352)
* refactor(components): [select&select-v2] refactor components

* refactor(components): [select-v2]

* refactor(components): update

* refactor(components): update

* refactor(components): [select-v2]

update

* refactor(components): update

* refactor(components): update

* refactor(components): update type

* refactor(components): update

* refactor(components): update

* refactor(components): update style

* refactor(components): update docs

* refactor(components): update

* refactor(components): fix #15323

* refactor(theme-chalk): update

* refactor(components): update

* refactor(components): update

* refactor(components): update

* refactor(components): fix bugs

* fix(components): fix issue

* fix(components): update

* fix(components): fix some bug

* feat(components): update

* feat(components): add tag slot

* feat(components): update

* fix(components): update

* style(theme-chalk): update style

* fix(theme-chalk): update

* feat(theme-chalk): update

* fix(components): update

* feat: update

* feat: update

* feat: update

* feat(components): update
2024-01-10 11:14:58 +08:00

49 lines
1.2 KiB
TypeScript

import { defineComponent, inject, watch } from 'vue'
import { selectKey } from '@element-plus/components/select'
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)) {
select.states.cachedOptions.set(item.value, item)
}
})
// fork from packages/select/src/useSelect.ts#330
const inputs = select.selectRef?.querySelectorAll('input') || []
if (
!Array.from(inputs).includes(
document.activeElement as HTMLInputElement
)
) {
select.setSelected()
}
},
{ flush: 'post', immediate: true }
)
return () => undefined
},
})