Skip to content

Commit

Permalink
fix(base-select): fix data display error when set disabled and hover-…
Browse files Browse the repository at this point in the history
…expand
  • Loading branch information
kagol committed Nov 18, 2024
1 parent 808af1f commit 85e6737
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 50 deletions.
17 changes: 17 additions & 0 deletions packages/renderless/src/base-select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,23 @@ export const watchShowClose =
}

// 以下为tiny 新增功能
/**
* 兼容不同主题多选禁用的展示类型
* default 和 smb 主题,displayOnly 时显示为 tagText,否则为 tag
* aurora 主题 displayOnly||disabled 时显示为tagText,否则为 tag
*/
export const computedShowTagText =
({ state }) =>
() =>
state.isDisplayOnly

/**
* 兼容不同主题多选,tag 在disabled 和 required 时是否显示关闭按钮的区别
* default 主题 ,禁用显示关闭按钮,required目前和aurora保持一致不显示,待设计图补充时更新
* aurora 主题,禁用时无禁用效果,required 时不显示关闭按钮
*/
export const isTagClosable = () => (item) => !item.required

export const computedGetIcon =
({ designConfig, props }) =>
() => {
Expand Down
12 changes: 10 additions & 2 deletions packages/renderless/src/base-select/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ import {
onClickCollapseTag,
computedIsExpand,
updateSelectedData,
hidePanel
hidePanel,
computedShowTagText,
isTagClosable
} from './index'
import debounce from '../common/deps/debounce'
import { isNumber } from '../common/type'
Expand Down Expand Up @@ -154,7 +156,9 @@ export const api = [
'clearSearchText',
'onClickCollapseTag',
'updateSelectedData',
'hidePanel'
'hidePanel',
'computedShowTagText',
'isTagClosable'
]

const initState = ({ reactive, computed, props, api, emitter, parent, constants, useBreakpoint, vm, designConfig }) => {
Expand Down Expand Up @@ -271,6 +275,8 @@ const initStateAdd = ({ computed, props, api, parent }) => {
formItemSize: computed(() => (parent.formItem || { state: {} }).state.formItemSize),
selectDisabled: computed(() => api.computedSelectDisabled()),
isDisplayOnly: computed(() => props.displayOnly || (parent.form || {}).displayOnly),
isDisabled: computed(() => props.disabled || (parent.form || {}).disabled),
isShowTagText: computed(() => api.computedShowTagText()),
gridCheckedData: computed(() => api.getcheckedData()),
searchSingleCopy: computed(() => props.allowCopy && !props.multiple && props.filterable),
childrenName: computed(() => 'children'),
Expand Down Expand Up @@ -364,6 +370,8 @@ const initApi = ({
computedGetTagType: computedGetTagType({ designConfig, props }),
clearSearchText: clearSearchText({ state, api }),
clearNoMatchValue: clearNoMatchValue({ props, emit }),
computedShowTagText: computedShowTagText({ state }),
isTagClosable: isTagClosable(),
updateSelectedData: updateSelectedData({ state }),
hidePanel: hidePanel({ state })
})
Expand Down
4 changes: 4 additions & 0 deletions packages/vue/src/base-select/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ export default defineComponent({
allText: {
type: String,
default: ''
},
showAllTextTag: {
type: Boolean,
default: false
}
},
setup(props, context) {
Expand Down
123 changes: 75 additions & 48 deletions packages/vue/src/base-select/src/pc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@
</tiny-filter-box>
<div
ref="tags"
:class="['tiny-base-select__tags', { 'is-showicon': slots.prefix, 'not-selected': !state.selected.length }]"
:class="[
'tiny-base-select__tags',
{ 'is-showicon': slots.prefix, 'not-selected': !state.selected.length },
{ 'is-show-tag': !state.isShowTagText }
]"
v-if="multiple && !state.isDisplayOnly && !shape"
:style="state.tagsStyle"
>
<span v-if="!state.selectDisabled">
<span v-if="!state.isShowTagText">
<span v-if="collapseTags && state.selected.length">
<tiny-tag
:closable="!state.selectDisabled"
Expand Down Expand Up @@ -119,66 +123,88 @@
<span class="tiny-base-select__tags-text">+ {{ state.selected.length - 1 }}</span>
</tiny-tag>
</span>
<!-- 显示所有标签的循环 -->
<span ref="tags-content" v-if="!collapseTags">
<!-- 当 showAllTextTag 时, 用all-text属性做为tag。 xdesign规范 -->
<tiny-tag
v-if="hoverExpand || clickExpand"
:class="['tiny-base-select__tags-collapse', { 'is-hidden': state.isHidden }]"
v-if="showAllTextTag && state.selectCls === 'checked-sur'"
:type="state.getTagType"
key="tags-collapse"
data-tag="tags-collapse"
:closable="false"
key="tags-all-text-tag"
data-tag="tags-all-text-tag"
:disabled="state.isDisabled"
:closable="true"
:size="state.collapseTagSize"
@click="onClickCollapseTag($event)"
@close="toggleCheckAll(false)"
>
<template v-if="hoverExpand"> + {{ state.collapseTagsLength }} </template>
<icon-ellipsis v-else></icon-ellipsis>
{{ allText || t('ui.base.all') }}
</tiny-tag>
<tiny-tag
v-for="(item, index) in state.selected"
:key="getValueKey(item)"
:class="{ 'not-visible': state.toHideIndex <= index && !state.isExpand }"
:closable="!item.disabled && !item.required"
:size="state.collapseTagSize"
:hit="item.state ? item.state.hitState : item.hitState"
:type="state.getTagType"
@close="deleteTag($event, item)"
disable-transitions
>
<tiny-tooltip
effect="light"
placement="top"
@mouseenter.native="handleEnterTag($event, getValueKey(item))"
<!-- 当非 showAllTextTag 时,原来的模式渲染 -->
<template v-else>
<tiny-tag
v-if="hoverExpand || clickExpand"
:class="['tiny-base-select__tags-collapse', { 'is-hidden': state.isHidden || state.isDisabled }]"
:type="state.getTagType"
key="tags-collapse"
data-tag="tags-collapse"
only-icon
:closable="false"
:size="state.collapseTagSize"
@click="onClickCollapseTag($event)"
>
<span v-if="!state.visible && state.overflow === index" class="tiny-base-select__tags-text">
{{ item.state ? item.state.currentLabel + '... ' : item.currentLabel + '... ' }}
</span>
<span v-else class="tiny-base-select__tags-text">
<slot name="label" :item="getLabelSlotValue(item)">
{{ item.state ? item.state.currentLabel : item.currentLabel }}
</slot>
</span>
<template v-if="state.tooltipContent[getValueKey(item)]" #content>
<span v-if="!state.visible && state.overflow === index">
<template v-if="hoverExpand"> + {{ state.collapseTagsLength }} </template>
<icon-ellipsis v-else></icon-ellipsis>
</tiny-tag>
<tiny-tag
v-for="(item, index) in state.selected"
:key="getValueKey(item)"
:class="{
'not-visible': state.toHideIndex <= index && !state.isExpand,
'is-required': item.required
}"
:closable="isTagClosable(item)"
:disabled="state.isDisabled || item.disabled"
:size="state.collapseTagSize"
:hit="item.state ? item.state.hitState : item.hitState"
:type="state.getTagType"
@close="deleteTag($event, item)"
disable-transitions
>
<tiny-tooltip
effect="light"
placement="top"
@mouseenter.native="handleEnterTag($event, getValueKey(item))"
>
<span v-if="!state.visible && state.overflow === index" class="tiny-base-select__tags-text">
{{ item.state ? item.state.currentLabel + '... ' : item.currentLabel + '... ' }}
</span>
<span v-else>
<span v-else class="tiny-base-select__tags-text">
<slot name="label" :item="getLabelSlotValue(item)">
{{ item.state ? item.state.currentLabel : item.currentLabel }}
</slot>
</span>
</template>
</tiny-tooltip>
</tiny-tag>
<template v-if="state.tooltipContent[getValueKey(item)]" #content>
<span v-if="!state.visible && state.overflow === index">
{{ item.state ? item.state.currentLabel + '... ' : item.currentLabel + '... ' }}
</span>
<span v-else>
<slot name="label" :item="getLabelSlotValue(item)">
{{ item.state ? item.state.currentLabel : item.currentLabel }}
</slot>
</span>
</template>
</tiny-tooltip>
</tiny-tag>

<!-- 收起按钮 -->
<span
v-if="clickExpand && state.showCollapseTag"
class="tiny-base-select__collapse-text"
@click="onClickCollapseTag($event)"
>
{{ t('ui.select.collapse') }}
<icon-chevron-up></icon-chevron-up>
</span>
<!-- 收起按钮 -->
<span
v-if="clickExpand && state.showCollapseTag"
class="tiny-base-select__collapse-text"
@click="onClickCollapseTag($event)"
>
{{ t('ui.select.collapse') }}
<icon-chevron-up></icon-chevron-up>
</span>
</template>
</span>
</span>

Expand Down Expand Up @@ -694,6 +720,7 @@ export default defineComponent({
'showProportion',
'clickExpand',
'maxVisibleRows',
'showAllTextTag',
'allText'
],
setup(props, context) {
Expand Down

0 comments on commit 85e6737

Please sign in to comment.