Skip to content

Commit cfe0021

Browse files
committed
feat: tree-select support searchValue
1 parent 41ee8ea commit cfe0021

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

components/tree-select/index.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| multiple | Support multiple or not, will be `true` when enable `treeCheckable`. | boolean | false |
1919
| placeholder | Placeholder of the select input | string\|slot | - |
2020
| searchPlaceholder | Placeholder of the search input | string\|slot | - |
21+
| searchValue(.sync) | work with `search` event to make search value controlled. | string | - |
2122
| showCheckedStrategy | The way show selected item in box. **Default:** just show child nodes. **`TreeSelect.SHOW_ALL`:** show all checked treeNodes (include parent treeNode). **`TreeSelect.SHOW_PARENT`:** show checked treeNodes (just show parent treeNode). | enum { TreeSelect.SHOW_ALL, TreeSelect.SHOW_PARENT, TreeSelect.SHOW_CHILD } | TreeSelect.SHOW_CHILD |
2223
| showSearch | Whether to display a search input in the dropdown menu(valid only in the single mode) | boolean | false |
2324
| size | To set the size of the select input, options: `large` `small` | string | 'default' |

components/tree-select/index.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ const TreeSelect = {
2828
prop: 'value',
2929
event: 'change',
3030
},
31-
31+
inject: {
32+
configProvider: { default: {}},
33+
},
3234
created () {
3335
warning(
3436
this.multiple !== false || !this.treeCheckable,
@@ -94,8 +96,10 @@ const TreeSelect = {
9496
notFoundContent,
9597
dropdownStyle,
9698
dropdownClassName,
99+
getPopupContainer,
97100
...restProps
98101
} = props
102+
const { getPopupContainer: getContextPopupContainer } = this.configProvider
99103
const rest = omit(restProps, ['inputIcon', 'removeIcon', 'clearIcon', 'switcherIcon', 'suffixIcon'])
100104
let suffixIcon = getComponentFromProp(this, 'suffixIcon')
101105
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon
@@ -131,6 +135,7 @@ const TreeSelect = {
131135
removeIcon,
132136
clearIcon,
133137
...rest,
138+
getPopupContainer: getPopupContainer || getContextPopupContainer,
134139
dropdownClassName: classNames(dropdownClassName, `${prefixCls}-tree-dropdown`),
135140
prefixCls,
136141
dropdownStyle: { maxHeight: '100vh', overflow: 'auto', ...dropdownStyle },

components/tree-select/index.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| multiple | 支持多选(当设置 treeCheckable 时自动变为true) | boolean | false |
1919
| placeholder | 选择框默认文字 | string\|slot | - |
2020
| searchPlaceholder | 搜索框默认文字 | string\|slot | - |
21+
| searchValue(.sync) | 搜索框的值,可以通过 `search` 事件获取用户输入 | string | - |
2122
| showCheckedStrategy | 定义选中项回填的方式。`TreeSelect.SHOW_ALL`: 显示所有选中节点(包括父节点). `TreeSelect.SHOW_PARENT`: 只显示父节点(当父节点下所有子节点都选中时). 默认只显示子节点. | enum{TreeSelect.SHOW_ALL, TreeSelect.SHOW_PARENT, TreeSelect.SHOW_CHILD } | TreeSelect.SHOW_CHILD |
2223
| showSearch | 在下拉中显示搜索框(仅在单选模式下生效) | boolean | false |
2324
| size | 选择框大小,可选 `large` `small` | string | 'default' |

components/tree-select/interface.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const TreeSelectProps = () => ({
2626
// onChange: (value: any, label: any) => void,
2727
// onSearch: (value: any) => void,
2828
searchPlaceholder: PropTypes.string,
29+
searchValue: PropTypes.string,
2930
showCheckedStrategy: PropTypes.oneOf(['SHOW_ALL', 'SHOW_PARENT', 'SHOW_CHILD']),
3031
suffixIcon: PropTypes.any,
3132
treeCheckable: PropTypes.bool,

components/vc-tree-select/src/Select.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ const Select = {
644644
// We should also trigger onSearch with empty string here
645645
// since if user use `treeExpandedKeys`, it need user have the ability to reset it.
646646
if (searchValue && searchValue.length) {
647+
this.__emit('update:searchValue', '')
647648
this.__emit('search', '')
648649
}
649650
}
@@ -754,6 +755,7 @@ const Select = {
754755
onSearchInputChange ({ target: { value }}) {
755756
const { _treeNodes: treeNodes, _valueEntities: valueEntities } = this.$data
756757
const { filterTreeNode, treeNodeFilterProp } = this.$props
758+
this.__emit('update:searchValue', value)
757759
this.__emit('search', value)
758760

759761
let isSet = false

0 commit comments

Comments
 (0)