Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): [select] fix the problem of multiple selection of hover … #2566

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions packages/renderless/src/select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ export const resetInputHeight =
api.calcCollapseTags()
}

const sizeInMap = designConfig?.state.initialInputHeight || Math.round(state.initialInputHeight) || 32
const noSelected = state.selected.length === 0
// tiny 新增的spacing (design中配置:aui为4,smb为0,tiny 默认为0)
const spacingHeight = designConfig?.state?.spacingHeight ?? constants.SPACING_HEIGHT
Expand All @@ -750,11 +749,11 @@ export const resetInputHeight =
const tagsClientHeight = tags.clientHeight

fastdom.mutate(() => {
input.style.height = Math.max(tagsClientHeight + spacingHeight, sizeInMap) + 'px'
input.style.height = Math.max(tagsClientHeight + spacingHeight, state.currentSizeMap) + 'px'
})
})
} else {
input.style.height = noSelected ? sizeInMap + 'px' : Math.max(0, sizeInMap) + 'px'
input.style.height = noSelected ? state.currentSizeMap + 'px' : Math.max(0, state.currentSizeMap) + 'px'
}
} else {
input.style.height = 'auto'
Expand Down Expand Up @@ -2049,6 +2048,15 @@ export const initQuery =
return Promise.resolve(selected)
}

export const computedCurrentSizeMap =
({ state, designConfig }) =>
() => {
const defaultSizeMap = { default: 32, mini: 24, small: 28, medium: 40 }
const sizeMap = designConfig?.state?.sizeMap || defaultSizeMap

return sizeMap[state.selectSize || 'default']
}

export const mounted =
({ api, parent, state, props, vm, designConfig }) =>
() => {
Expand All @@ -2064,18 +2072,10 @@ export const mounted =

state.completed = true

// tiny 新增: sizeMap适配不同主题
const defaultSizeMap = { default: 32, mini: 24, small: 36, medium: 40 }
const sizeMap = designConfig?.state?.sizeMap || defaultSizeMap

if (props.multiple && Array.isArray(props.modelValue) && props.modelValue.length > 0) {
state.currentPlaceholder = ''
}

state.initialInputHeight = state.isDisplayOnly
? sizeMap[state.selectSize || 'default'] // tiny 新增 : default, aui只处理了另3种情况,不传入时,要固定为default
: inputClientRect.height || sizeMap[state.selectSize]

addResizeListener(parentEl, api.handleResize)

if (vm.$refs.tags) {
Expand Down
9 changes: 6 additions & 3 deletions packages/renderless/src/select/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ import {
onClickCollapseTag,
computedIsExpand,
computedShowTagText,
isTagClosable
isTagClosable,
computedCurrentSizeMap
} from './index'
import debounce from '../common/deps/debounce'
import { isNumber } from '../common/type'
Expand Down Expand Up @@ -243,7 +244,8 @@ const initState = ({ reactive, computed, props, api, emitter, parent, constants,
}
return true // tiny 默认为true
})(),
designConfig
designConfig,
currentSizeMap: computed(() => api.computedCurrentSizeMap())
})

return state
Expand Down Expand Up @@ -404,7 +406,8 @@ const initApi = ({
clearSearchText: clearSearchText({ state, api }),
clearNoMatchValue: clearNoMatchValue({ props, emit }),
computedShowTagText: computedShowTagText({ state }),
isTagClosable: isTagClosable()
isTagClosable: isTagClosable(),
computedCurrentSizeMap: computedCurrentSizeMap({ state, designConfig })
})

addApi({ api, props, state, emit, constants, parent, nextTick, dispatch, vm, isMobileFirstMode, designConfig })
Expand Down
1 change: 1 addition & 0 deletions packages/theme/src/option/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
vertical-align: top;
}
}

Expand Down
21 changes: 7 additions & 14 deletions packages/theme/src/select/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,15 @@
}
}

&.tiny-select__multiple.is-display-only {
&.is-hover-expand,
&.is-click-expand {
vertical-align: top;
}
}

&.is-hover-expand,
&.is-click-expand {
vertical-align: top;

.@{select-prefix-cls}__tags-group {
position: absolute;
top: 0;
Expand Down Expand Up @@ -307,18 +312,6 @@
position: absolute;
width: 100%;
}

&.@{select-prefix-cls}--small {
.@{select-prefix-cls}__tags {
padding-top: 2px;
}
}

&.@{select-prefix-cls}--mini {
.@{select-prefix-cls}__tags {
padding-top: 2px;
}
}
}

&.is-hover-expand.is-disabled {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/select/src/pc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
:type="state.getTagType"
key="tags-collapse"
data-tag="tags-collapse"
only-icon
:only-icon="!hoverExpand"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure hoverExpand prop is defined to prevent runtime errors

The hoverExpand property is used in the template but is not currently defined as a prop or within the component's data or computed properties. This could lead to runtime errors due to accessing an undefined property.

Apply this diff to define hoverExpand as a prop:

  props: [
    ...props,
    // 以下为 tiny 新增
    'searchable',
    'showEmptyImage',
    'inputBoxType',
    'tagType',
    'clearNoMatchValue',
    'showLimitText',
    'showProportion',
    'clickExpand',
    'maxVisibleRows',
    'showAllTextTag',
    'allText',
+   'hoverExpand'
  ],

Committable suggestion skipped: line range outside the PR's diff.

:closable="false"
:size="state.collapseTagSize"
@click="onClickCollapseTag($event)"
Expand Down