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

feat: select supports prepend #2006

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions packages/web-vue/components/select/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ description: When users need to select one or more from a group of similar data,

@import ./__demo__/label.md

@import ./__demo__/prepend.md

@import ./__demo__/linkage.md

@import ./__demo__/field-names.md
Expand Down
2 changes: 2 additions & 0 deletions packages/web-vue/components/select/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ description: 当用户需要从一组同类数据中选择一个或多个时,

@import ./__demo__/label.md

@import ./__demo__/prepend.md

@import ./__demo__/linkage.md

@import ./__demo__/field-names.md
Expand Down
14 changes: 11 additions & 3 deletions packages/web-vue/components/select/__demo__/label.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ The display content of the select box can be customized through the `#label` slo

```vue
<template>
<a-select default-value="Beijing" :style="{width:'320px'}" placeholder="Please select ...">
<a-select
default-value="Beijing"
:style="{ width: '320px' }"
placeholder="Please select ..."
>
<template #label="{ data }">
<span><icon-plus/>{{data?.label}}</span>
<span><icon-plus />{{ data?.label }}</span>
</template>

<template #prepend>
<div>addBefore</div>
</template>
<a-option>Beijing</a-option>
<a-option>Shanghai</a-option>
Expand All @@ -33,7 +41,7 @@ The display content of the select box can be customized through the `#label` slo
import { IconPlus } from '@arco-design/web-vue/es/icon';

export default {
components: { IconPlus }
components: { IconPlus },
};
</script>
```
35 changes: 35 additions & 0 deletions packages/web-vue/components/select/__demo__/prepend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
```yaml
title:
zh-CN: 前置标签
en-US: Prepend
```

## zh-CN

通过 `#prepend` 插槽可以自定义选择框前置标签

---

## en-US

The display content of the select box can be customized through the `#prepend` slot.

---

```vue
<template>
<a-select
default-value="Beijing"
:style="{ width: '320px' }"
placeholder="Please select ..."
>
<template #prepend>
<div>Select City</div>
</template>
<a-option>Beijing</a-option>
<a-option>Shanghai</a-option>
<a-option>Guangzhou</a-option>
<a-option disabled>Disabled</a-option>
</a-select>
</template>
```
12 changes: 11 additions & 1 deletion packages/web-vue/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ export default defineComponent({
return data?.label ?? '';
};

return () => (
const renderTriggerNode = () => (
<Trigger
v-slots={{ content: renderDropDown }}
trigger="click"
Expand Down Expand Up @@ -957,5 +957,15 @@ export default defineComponent({
)}
</Trigger>
);

if (slots.prepend) {
return () => (
<div class={`${prefixCls}-wrapper`}>
<div class={`${prefixCls}-prepend`}>{slots.prepend?.()}</div>
{renderTriggerNode()}
</div>
);
}
return renderTriggerNode;
},
});
8 changes: 8 additions & 0 deletions packages/web-vue/components/select/style/index.less
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
@import '../../style/mixins/index.less';
@import './mixin.less';
@import './token.less';

@select-prefix-cls: ~'@{prefix}-select';

.@{select-prefix-cls}-wrapper {
display: inline-flex;
align-items: stretch;

.select-prepend(@select-prefix-cls);
}

.@{select-prefix-cls}-dropdown {
box-sizing: border-box;
padding: @select-popup-padding-vertical 0;
Expand Down
16 changes: 16 additions & 0 deletions packages/web-vue/components/select/style/mixin.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import '../../input/style/token.less';

.select-prepend(@cls) {
.@{cls}-prepend {
display: flex;
align-items: center;
padding: 0 @input-padding-horizontal;
color: @input-color-text;
white-space: nowrap;
background-color: @input-color-addon-bg;
border: 1px solid @input-color-addon-border_default;
border-right: @input-border-addon-separator-width solid
@input-color-addon-border;
border-bottom-left-radius: @input-border-radius;
}
}