浏览代码

fix: [TreeSelect]maxTagCount does not take effect when searchPosition is trigger #498 (#499)

Co-authored-by: chenyuling <[email protected]>
boomboomchen 3 年之前
父节点
当前提交
670b311f1c

+ 5 - 0
packages/semi-ui/treeSelect/__test__/treeMultiple.test.js

@@ -632,7 +632,12 @@ describe('TreeSelect', () => {
             searchPosition: 'trigger',
             filterTreeNode: true,
             multiple: true,
+            maxTagCount: 1,
+            defaultValue: ['Zhongguo', 'Meiguo']
         });
+        const selection = treeSelect.find(`.${BASE_CLASS_PREFIX}-tree-select .${BASE_CLASS_PREFIX}-tree-select-selection`);
+        expect(selection.find(`.${BASE_CLASS_PREFIX}-tagInput .${BASE_CLASS_PREFIX}-tag`).length).toEqual(1);
+        expect(selection.find(`.${BASE_CLASS_PREFIX}-tagInput .${BASE_CLASS_PREFIX}-tagInput-wrapper-n`).at(0).getDOMNode().textContent).toEqual('+1');
         const input = treeSelect.find(`.${BASE_CLASS_PREFIX}-tree-select .${BASE_CLASS_PREFIX}-tagInput .${BASE_CLASS_PREFIX}-input`);
         const searchValue = '北';
         const event = { target: { value: searchValue } };

+ 12 - 0
packages/semi-ui/treeSelect/_story/treeSelect.stories.js

@@ -299,6 +299,18 @@ export const SearchPosition = () => (
       placeholder="searchAutoFocus"
       searchAutoFocus
     />
+    <br />
+    <br />
+    <TreeSelect
+      searchPosition="trigger"
+      style={{ width: 300 }}
+      dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
+      treeData={treeData2}
+      multiple
+      filterTreeNode
+      maxTagCount={1}
+      placeholder="maxTagCount=1"
+    />
   </>
 );
 

+ 2 - 0
packages/semi-ui/treeSelect/index.tsx

@@ -979,6 +979,7 @@ class TreeSelect extends BaseComponent<TreeSelectProps, TreeSelectState> {
             size,
             searchAutoFocus,
             placeholder,
+            maxTagCount,
         } = this.props;
         const {
             keyEntities,
@@ -988,6 +989,7 @@ class TreeSelect extends BaseComponent<TreeSelectProps, TreeSelectState> {
         const keyList = normalizeKeyList(checkedKeys, keyEntities, leafOnly);
         return (
             <TagInput
+                maxTagCount={maxTagCount}
                 disabled={disabled}
                 onInputChange={v => this.search(v)}
                 ref={this.tagInputRef}