Browse Source

feat: add search ref method on select (#1602)

YannLynn 2 years ago
parent
commit
74cb62bbd8

+ 1 - 0
content/input/select/index-en-US.md

@@ -1419,6 +1419,7 @@ Some internal methods provided by Select can be accessed through ref:
 | focus       | Manually focus select           | v1.11.0 |
 | open        | Manually open dropdown list     | v0.34.0 |
 | selectAll   | Manually select all options     | v1.18.0 |
+| search(value: string, event: event)  | You can call this method through ref to search, and the search value will be set to Input          | v2.35.0 |
 
 ## Accessibility
 

+ 1 - 0
content/input/select/index.md

@@ -1485,6 +1485,7 @@ import { Select, Checkbox } from '@douyinfe/semi-ui';
 | clearInput  | 调用时可以手动清空 input 搜索框的值 | v1.18.0 |
 | deselectAll | 调用时可以手动清空所有已选项        | v1.18.0 |
 | selectAll   | 调用时可以选中所有 Option           | v1.18.0 |
+| search(value: string, event: event)| 可通过 ref 调用该方法进行搜索,该搜索值会被置给 Input   | v2.35.0 |
 
 ## Accessibility
 

+ 4 - 1
packages/semi-ui/select/index.tsx

@@ -658,7 +658,7 @@ class Select extends BaseComponent<SelectProps, SelectState> {
         }
     }
 
-    handleInputChange = (value: string, event: React.KeyboardEvent) => this.foundation.handleInputChange(value, event);
+    handleInputChange = (value: string, event: React.ChangeEvent<HTMLInputElement>) => this.foundation.handleInputChange(value, event);
 
     renderInput() {
         const { size, multiple, disabled, inputProps, filter } = this.props;
@@ -739,6 +739,9 @@ class Select extends BaseComponent<SelectProps, SelectState> {
         this.foundation.handleClearClick(e as any);
     }
 
+    search(value: string, event: React.ChangeEvent<HTMLInputElement>) {
+        this.handleInputChange(value, event);
+    }
 
     renderEmpty() {
         return <Option empty={true} emptyContent={this.props.emptyContent} />;