diff --git a/packages/fighting-design/option/src/option.vue b/packages/fighting-design/option/src/option.vue index 8f07c5ecc4..50983567fa 100644 --- a/packages/fighting-design/option/src/option.vue +++ b/packages/fighting-design/option/src/option.vue @@ -21,24 +21,32 @@ /** 获取到 trigger 注入的依赖项 */ const triggerInject: TriggerProvide | null = inject(TRIGGER_CLOSE_KEY, null) + /** 获取插槽内容 */ + const slotLabel = computed((): string => { + if (!slot.default) { + return '' + } + + const _slot: VNodeNormalizedChildren | string = slot.default()[0].children + + return isString(_slot) ? _slot : '' + }) + /** 控制是否显示 */ - const isVisible = computed(() => { + const isVisible = computed((): boolean => { // 父组件没有依赖则不显示 if (!parentInject) { return false } + // 没有 filter 属性,则展示 if (!parentInject.filter) { return true } - const slotText: VNodeNormalizedChildren | string | undefined = - slot.default && slot.default()[0].children - - const label = isString(slotText) - ? slotText - : '' || prop.label.toString() || prop.value.toString() - + /** 获取到 label */ + const label = slotLabel.value || prop.label.toString() || prop.value.toString() + /** 获取到选中的项目 */ const currentItem = parentInject.childrenLabels.find(item => { return item.slot === label }) @@ -50,17 +58,6 @@ return true }) - /** 获取插槽内容 */ - const slotLabel = computed((): string => { - if (!slot.default) { - return '' - } - - const _slot: VNodeNormalizedChildren | string = slot.default()[0].children - - return isString(_slot) ? _slot : '' - }) - /** 标签选中状态 */ const labelActive = computed((): boolean => { /** 获取到 value 的值 */ @@ -161,11 +158,11 @@