Browse Source

docs: [TreeSelect] custom trigger example optimization (#1521)

YyumeiZhang 2 years ago
parent
commit
340d9543cc

+ 5 - 4
content/input/treeselect/index-en-US.md

@@ -1225,8 +1225,8 @@ interface triggerRenderProps {
     /* It is used to start the search when the value of the Input box is updated. 
     /* It is used to start the search when the value of the Input box is updated. 
      * When you update the value of the Input component customized by triggerRender, 
      * When you update the value of the Input component customized by triggerRender, 
      * you should call this function to synchronize the state with the TreeSelect 
      * you should call this function to synchronize the state with the TreeSelect 
-     * internally. you need to set the filterTreeNode parameter to non-false when use it
-     * It is supported from v2.32.0
+     * internally. you need to set the filterTreeNode parameter to non-false when use it,
+     * and set searchPosition to 'trigger'. It is supported from v2.32.0
      */
      */
     onSearch: inputValue => void;   
     onSearch: inputValue => void;   
 }
 }
@@ -1275,7 +1275,7 @@ function Demo() {
     });
     });
 
 
     const renderTrigger = useCallback((props) => {
     const renderTrigger = useCallback((props) => {
-        const { value, onSearch, onRemove } = props;
+        const { value, onSearch, onRemove, inputValue } = props;
         const tagInputValue = value.map(item => item.key);
         const tagInputValue = value.map(item => item.key);
         const renderTagInMultiple = (key) => {
         const renderTagInMultiple = (key) => {
             const label = value.find(item => item.key === key).label;
             const label = value.find(item => item.key === key).label;
@@ -1286,7 +1286,7 @@ function Demo() {
         };
         };
         return (
         return (
             <TagInput
             <TagInput
-                style={{ width: 250 }}
+                inputValue={inputValue}
                 value={tagInputValue}
                 value={tagInputValue}
                 onInputChange={onSearch}
                 onInputChange={onSearch}
                 renderTagItem={renderTagInMultiple}
                 renderTagItem={renderTagInMultiple}
@@ -1298,6 +1298,7 @@ function Demo() {
         <TreeSelect
         <TreeSelect
             triggerRender={renderTrigger}
             triggerRender={renderTrigger}
             filterTreeNode
             filterTreeNode
+            searchPosition="trigger"
             multiple
             multiple
             treeData={treeData}
             treeData={treeData}
             placeholder='Custom Trigger'
             placeholder='Custom Trigger'

+ 4 - 2
content/input/treeselect/index.md

@@ -1193,6 +1193,7 @@ interface TriggerRenderProps {
      * 用于在 Input 框值更新时候启动搜索,当你在 triggerRender 自定义的
      * 用于在 Input 框值更新时候启动搜索,当你在 triggerRender 自定义的
      * Input 组件值更新时,你应该调用该函数,用于向 TreeSelect 内部
      * Input 组件值更新时,你应该调用该函数,用于向 TreeSelect 内部
      * 同步状态, 使用同时需要设置 filterTreeNode 参数非 false, 
      * 同步状态, 使用同时需要设置 filterTreeNode 参数非 false, 
+     * searchPosition 为 'trigger'
      * 从 v2.32.0 版本开始支持
      * 从 v2.32.0 版本开始支持
     */
     */
     onSearch: inputValue => void;   
     onSearch: inputValue => void;   
@@ -1241,7 +1242,7 @@ function Demo() {
     });
     });
 
 
     const renderTrigger = useCallback((props) => {
     const renderTrigger = useCallback((props) => {
-        const { value, onSearch, onRemove } = props;
+        const { value, onSearch, onRemove, inputValue } = props;
         const tagInputValue = value.map(item => item.key);
         const tagInputValue = value.map(item => item.key);
         const renderTagInMultiple = (key) => {
         const renderTagInMultiple = (key) => {
             const label = value.find(item => item.key === key).label;
             const label = value.find(item => item.key === key).label;
@@ -1252,7 +1253,7 @@ function Demo() {
         };
         };
         return (
         return (
             <TagInput
             <TagInput
-                style={{ width: 250 }}
+                inputValue={inputValue}
                 value={tagInputValue}
                 value={tagInputValue}
                 onInputChange={onSearch}
                 onInputChange={onSearch}
                 renderTagItem={renderTagInMultiple}
                 renderTagItem={renderTagInMultiple}
@@ -1264,6 +1265,7 @@ function Demo() {
         <TreeSelect
         <TreeSelect
             triggerRender={renderTrigger}
             triggerRender={renderTrigger}
             filterTreeNode
             filterTreeNode
+            searchPosition="trigger"
             multiple
             multiple
             treeData={treeData}
             treeData={treeData}
             placeholder='Custom Trigger'
             placeholder='Custom Trigger'

+ 1 - 1
packages/semi-foundation/treeSelect/foundation.ts

@@ -49,7 +49,7 @@ export interface BasicTriggerRenderProps {
     value: BasicTreeNodeData[];
     value: BasicTreeNodeData[];
     onClear: (e: any) => void;
     onClear: (e: any) => void;
     onSearch: (inputValue: string) => void;
     onSearch: (inputValue: string) => void;
-    onRemove: (value: string) => void
+    onRemove: (key: string) => void
 }
 }
 
 
 export type BasicOnChangeWithObject = (node: BasicTreeNodeData[] | BasicTreeNodeData, e: any) => void;
 export type BasicOnChangeWithObject = (node: BasicTreeNodeData[] | BasicTreeNodeData, e: any) => void;

+ 4 - 2
packages/semi-ui/treeSelect/_story/treeSelect.stories.jsx

@@ -2197,7 +2197,7 @@ export const triggerRenderAddMethod = () => {
   }, []);
   }, []);
 
 
   const renderTrigger3 = useCallback((props) => {
   const renderTrigger3 = useCallback((props) => {
-    const { value, onSearch, onRemove } = props;
+    const { value, onSearch, onRemove, inputValue } = props;
     const tagInputValue = value.map(item => item.key);
     const tagInputValue = value.map(item => item.key);
     const renderTagInMultiple = (key) => {
     const renderTagInMultiple = (key) => {
       const label = value.find(item => item.key === key).label;
       const label = value.find(item => item.key === key).label;
@@ -2208,7 +2208,7 @@ export const triggerRenderAddMethod = () => {
     }
     }
     return (
     return (
       <TagInput
       <TagInput
-        style={{ width: 250 }}
+        inputValue={inputValue}
         value={tagInputValue}
         value={tagInputValue}
         onInputChange={onSearch}
         onInputChange={onSearch}
         renderTagItem={renderTagInMultiple}
         renderTagItem={renderTagInMultiple}
@@ -2230,6 +2230,7 @@ export const triggerRenderAddMethod = () => {
       <TreeSelect
       <TreeSelect
           triggerRender={renderTrigger2}
           triggerRender={renderTrigger2}
           filterTreeNode
           filterTreeNode
+          searchPosition="trigger"
           multiple
           multiple
           treeData={treeData}
           treeData={treeData}
           placeholder='Custom Trigger'
           placeholder='Custom Trigger'
@@ -2240,6 +2241,7 @@ export const triggerRenderAddMethod = () => {
       <TreeSelect
       <TreeSelect
           triggerRender={renderTrigger3}
           triggerRender={renderTrigger3}
           filterTreeNode
           filterTreeNode
+          searchPosition="trigger"
           multiple
           multiple
           treeData={treeData}
           treeData={treeData}
           placeholder='Custom Trigger'
           placeholder='Custom Trigger'