Skip to content

Commit

Permalink
feat(select): add tag prop
Browse files Browse the repository at this point in the history
  • Loading branch information
flsion committed Aug 16, 2024
1 parent 867cca0 commit 52b8d98
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export default defineComponent({
type: Number,
default: 0,
},
tagNowrap: {
type: Boolean,
default: false,
},
retainInputValue: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -190,6 +194,7 @@ export default defineComponent({
error={mergedError.value}
maxTagCount={props.maxTagCount}
disabledInput={!props.allowSearch && !props.allowCreate}
tagNowrap={props.tagNowrap}
retainInputValue
uninjectFormItemContext
onRemove={handleRemove}
Expand Down
10 changes: 10 additions & 0 deletions packages/web-vue/components/cascader/cascader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
:placeholder="placeholder"
:loading="loading"
:max-tag-count="maxTagCount"
:tag-nowrap="tagNowrap"
v-bind="$attrs"
@input-value-change="handleInputValueChange"
@clear="handleClear"
Expand Down Expand Up @@ -426,6 +427,15 @@ export default defineComponent({
virtualListProps: {
type: Object as PropType<VirtualListProps>,
},
/**
* @zh 标签内容不换行
* @en Tag content does not wrap
* @version 2.56.1
*/
tagNowrap: {
type: Boolean,
default: false,
},
},
emits: {
'update:modelValue': (
Expand Down
17 changes: 16 additions & 1 deletion packages/web-vue/components/input-tag/input-tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ export default defineComponent({
fieldNames: {
type: Object as PropType<InputTagFieldNames>,
},
/**
* @zh 标签内容不换行
* @en Tag content does not wrap
* @version 2.56.1
*/
tagNowrap: {
type: Boolean,
default: false,
},
// private
baseCls: String,
focused: Boolean,
Expand Down Expand Up @@ -531,7 +540,12 @@ export default defineComponent({
tag="span"
name="input-tag-zoom"
// @ts-ignore
class={`${prefixCls}-inner`}
class={[
`${prefixCls}-inner`,
{
[`${prefixCls}-nowrap`]: props.tagNowrap,
},
]}
>
{tags.value.map((item, index) => (
<Tag
Expand All @@ -541,6 +555,7 @@ export default defineComponent({
!mergedDisabled.value && !props.readonly && item.closable
}
visible
nowrap={props.tagNowrap}
{...item.tagProps}
onClose={(ev: MouseEvent) => handleRemove(item.value, index, ev)}
>
Expand Down
5 changes: 5 additions & 0 deletions packages/web-vue/components/input-tag/style/input-tag.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
overflow: hidden;
line-height: 0;

&.@{cls}-nowrap {
display: flex;
flex-wrap: wrap;
}

.@{cls}-tag {
display: inline-flex;
align-items: center;
Expand Down
10 changes: 10 additions & 0 deletions packages/web-vue/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ export default defineComponent({
type: Boolean as PropType<boolean>,
default: false,
},
/**
* @zh 标签内容不换行
* @en Tag content does not wrap
* @version 2.56.1
*/
tagNowrap: {
type: Boolean,
default: false,
},
},
emits: {
'update:modelValue': (
Expand Down Expand Up @@ -1002,6 +1011,7 @@ export default defineComponent({
placeholder={props.placeholder}
bordered={props.bordered}
size={mergedSize.value}
tagNowrap={props.tagNowrap}
// @ts-ignore
onInputValueChange={handleInputValueChange}
onRemove={handleRemove}
Expand Down
6 changes: 6 additions & 0 deletions packages/web-vue/components/tag/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
color: @tag-default-color-icon;
}

&-text {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

each(@colors, {
&&-checked&-@{value} {
color: ~'@{tag-@{value}-color-text}';
Expand Down
14 changes: 13 additions & 1 deletion packages/web-vue/components/tag/tag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<span v-if="$slots.icon" :class="`${prefixCls}-icon`">
<slot name="icon" />
</span>
<slot />
<span v-if="nowrap" :class="`${prefixCls}-text`">
<slot />
</span>
<slot v-else />
<icon-hover
v-if="closable"
role="button"
Expand Down Expand Up @@ -124,6 +127,15 @@ export default defineComponent({
type: Boolean,
default: true,
},
/**
* @zh 标签内容不换行
* @en Tag content does not wrap
* @version 2.56.1
*/
nowrap: {
type: Boolean,
default: false,
},
},
emits: {
'update:visible': (visible: boolean) => true,
Expand Down

0 comments on commit 52b8d98

Please sign in to comment.