mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* feat(components): [cascader] Hide radio in single mode * feat(components): [cascader] Renamed prop to \`selectOnClick\` * feat(components): [cascader] Update doc * feat(components): [cascader] Adjust how data is fetched * feat(components): [cascader] update type * Update packages/components/cascader-panel/src/node-content.ts Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> * feat(components): [cascader] Merge and fix v-model bug * feat(components): [cascader] Renamed to checkOnClickNode * feat(components): [cascader] Renamed to checkOnClickNode * feat(components): [cascader] merge * feat(components): [cascader] Add a check * feat(components): [cascader] Add test case * feat(components): [cascader] Fix type error * feat(components): [cascader] Add checkOnClickNode, showRadio props * feat(components): [cascader] Update doc * Update packages/components/cascader/src/cascader.ts Done, thanks! Co-authored-by: btea <2356281422@qq.com> * fix: showRadio defaults checkOnClickNode * test: showRadio fallback behavior * refactor: rename prop and support checkOnClickNode for multiple mode * doc:update * Update packages/components/cascader-panel/src/config.ts Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> * docs: tweak props * docs: update doc * chore: update doc & fix toggle check * Update docs/en-US/component/cascader.md Co-authored-by: btea <2356281422@qq.com> * Update docs/en-US/component/cascader.md Co-authored-by: btea <2356281422@qq.com> * Update docs/en-US/component/cascader.md Co-authored-by: btea <2356281422@qq.com> * Update cascader-panel.test.tsx --------- Co-authored-by: WANGXIAOYU1995 <109521682+WANGXIAOYU1995@users.noreply.github.com> Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> Co-authored-by: btea <2356281422@qq.com> Co-authored-by: Dsaquel <291874700n@gmail.com>
119 lines
2.4 KiB
Vue
119 lines
2.4 KiB
Vue
<template>
|
|
<li
|
|
v-show="visible"
|
|
:id="id"
|
|
:class="containerKls"
|
|
role="option"
|
|
:aria-disabled="isDisabled || undefined"
|
|
:aria-selected="itemSelected"
|
|
@mousemove="hoverItem"
|
|
@click.stop="selectOptionClick"
|
|
>
|
|
<slot>
|
|
<span>{{ currentLabel }}</span>
|
|
</slot>
|
|
</li>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import {
|
|
computed,
|
|
defineComponent,
|
|
getCurrentInstance,
|
|
nextTick,
|
|
onBeforeUnmount,
|
|
reactive,
|
|
toRefs,
|
|
unref,
|
|
} from 'vue'
|
|
import { useId, useNamespace } from '@element-plus/hooks'
|
|
import { useOption } from './useOption'
|
|
import { COMPONENT_NAME, optionProps } from './option'
|
|
|
|
import type {
|
|
OptionExposed,
|
|
OptionInternalInstance,
|
|
OptionStates,
|
|
} from './type'
|
|
|
|
export default defineComponent({
|
|
name: COMPONENT_NAME,
|
|
componentName: COMPONENT_NAME,
|
|
|
|
props: optionProps,
|
|
|
|
setup(props) {
|
|
const ns = useNamespace('select')
|
|
const id = useId()
|
|
|
|
const containerKls = computed(() => [
|
|
ns.be('dropdown', 'item'),
|
|
ns.is('disabled', unref(isDisabled)),
|
|
ns.is('selected', unref(itemSelected)),
|
|
ns.is('hovering', unref(hover)),
|
|
])
|
|
|
|
const states = reactive<OptionStates>({
|
|
index: -1,
|
|
groupDisabled: false,
|
|
visible: true,
|
|
hover: false,
|
|
})
|
|
|
|
const {
|
|
currentLabel,
|
|
itemSelected,
|
|
isDisabled,
|
|
select,
|
|
hoverItem,
|
|
updateOption,
|
|
} = useOption(props, states)
|
|
|
|
const { visible, hover } = toRefs(states)
|
|
|
|
const vm = (getCurrentInstance()! as OptionInternalInstance).proxy
|
|
|
|
select.onOptionCreate(vm)
|
|
|
|
onBeforeUnmount(() => {
|
|
const key = vm.value
|
|
|
|
// if option is not selected, remove it from cache
|
|
nextTick(() => {
|
|
const { selected: selectedOptions } = select.states
|
|
const doesSelected = selectedOptions.some((item) => {
|
|
return item.value === vm.value
|
|
})
|
|
if (select.states.cachedOptions.get(key) === vm && !doesSelected) {
|
|
select.states.cachedOptions.delete(key)
|
|
}
|
|
})
|
|
select.onOptionDestroy(key, vm)
|
|
})
|
|
|
|
function selectOptionClick() {
|
|
if (!isDisabled.value) {
|
|
select.handleOptionSelect(vm)
|
|
}
|
|
}
|
|
|
|
return {
|
|
ns,
|
|
id,
|
|
containerKls,
|
|
currentLabel,
|
|
itemSelected,
|
|
isDisabled,
|
|
select,
|
|
visible,
|
|
hover,
|
|
states,
|
|
|
|
hoverItem,
|
|
updateOption,
|
|
selectOptionClick,
|
|
} satisfies OptionExposed
|
|
},
|
|
})
|
|
</script>
|