Skip to content

Commit

Permalink
fix(select): fix issuse 128
Browse files Browse the repository at this point in the history
issuse-128,分组搜索

fix Tencent#128
  • Loading branch information
geff1991 committed Jan 23, 2022
1 parent c5ff9cc commit d3acf9a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
9 changes: 3 additions & 6 deletions examples/select/demos/group.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div class="tdesign-demo-select-base">
<!-- 方式一:直接传 options 数据,比插槽的方式更简单 -->
<t-select v-model="value1" :options="options" placeholder="请选择" />
<t-select v-model="value1" :options="options" placeholder="请选择" filterable />

<!-- 方式二:使用插槽节点 -->
<t-select v-model="value2" placeholder="请选择">
<t-select v-model="value2" placeholder="请选择" filterable>
<t-option-group
v-for="(list, index) in options"
:key="index"
Expand All @@ -28,10 +28,7 @@ export default {
options: [
{
group: '分组一',
children: [
{ label: '选项一', value: 1 },
{ label: '选项二', value: 2 },
],
children: [],
},
{
group: '分组二',
Expand Down
21 changes: 20 additions & 1 deletion src/select/optionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { prefix } from '../config';
import CLASSNAMES from '../utils/classnames';
import props from './option-group-props';
import { ClassName } from '../common';
import { TdOptionProps } from './type';

const name = `${prefix}-select-option-group`;

export interface Select extends Vue {
tSelect: {
size: string;
displayOptions: Array<TdOptionProps>;
};
}

Expand All @@ -33,10 +35,27 @@ export default (Vue as VueConstructor<Select>).extend({
];
},
},
watch: {
'tSelect.displayOptions': function () {
this.childrenChange();
},
},
data() {
return {
visible: true,
};
},
methods: {
childrenChange() {
this.visible = this.$children
&& Array.isArray(this.$children)
&& this.$children.some((option) => (option as any).show === true);
},
},
render(): VNode {
const children: ScopedSlotReturnValue = renderTNodeJSX(this, 'default');
return (
<li class={this.classes}>
<li v-show={this.visible} class={this.classes}>
<div class={`${name}__header`}>{this.label}</div>
<ul>{children}</ul>
</li>
Expand Down
6 changes: 1 addition & 5 deletions src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,6 @@ export default mixins(getConfigReceiverMixins<Vue, SelectConfig>('select')).exte
},
visibleChange(val: boolean) {
emitEvent<Parameters<TdSelectProps['onVisibleChange']>>(this, 'visible-change', val);
if (this.focusing && !val) {
this.visible = true;
return;
}
this.visible = val;
if (!val) {
this.searchInput = '';
Expand Down Expand Up @@ -603,7 +599,7 @@ export default mixins(getConfigReceiverMixins<Vue, SelectConfig>('select')).exte
{options.map((groupList: SelectOptionGroup) => {
const children = groupList.children.filter((item) => this.displayOptionsMap.get(item));
return (
<t-option-group label={groupList.group} divider={groupList.divider}>
<t-option-group v-show={children.length} label={groupList.group} divider={groupList.divider}>
{this.renderOptions(children)}
</t-option-group>
);
Expand Down
4 changes: 0 additions & 4 deletions src/tree-select/tree-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,6 @@ export default mixins(getConfigReceiverMixins<Vue, TreeSelectConfig>('treeSelect
},
methods: {
async popupVisibleChange(visible: boolean) {
if (this.focusing && !visible) {
this.visible = true;
return;
}
await (this.visible = visible);
if (this.showFilter && this.visible) {
const searchInput = this.$refs.input as HTMLElement;
Expand Down

0 comments on commit d3acf9a

Please sign in to comment.