Skip to content

Commit

Permalink
feat(tree-select): 新增自定义触发器功能(XiaoMi#2844)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangxuexue committed Jun 28, 2024
1 parent 668c9c6 commit 4192796
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
45 changes: 29 additions & 16 deletions packages/ui/tree-select/src/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const TreeSelect = forwardRef<HTMLDivElement | null, TreeSelectProps>(
customRender,
prefix,
suffix,
customRender,
...rest
},
ref
Expand Down Expand Up @@ -247,22 +248,30 @@ export const TreeSelect = forwardRef<HTMLDivElement | null, TreeSelectProps>(
onSearch={callAllFuncs(onSearchProp, onSearch)}
loading={rest.loading !== undefined ? rest.loading : loading}
trigger={
<MockInput
// disabled={disabled}
size={size}
clearable={clearable}
placeholder={placeholder}
displayRender={displayRenderProp}
prefix={prefix}
suffix={[menuVisible ? <UpOutlined /> : <DownOutlined />, suffix]}
focused={menuVisible}
value={value}
onChange={tryChangeValue}
data={mergedData}
// @ts-ignore
invalid={invalid}
appearance={appearance}
/>
customRender ? (
typeof customRender === 'function' ? (
customRender(selectedItem as TreeNodeEventData)
) : (
customRender
)
) : (
<MockInput
// disabled={disabled}
size={size}
clearable={clearable}
placeholder={placeholder}
displayRender={displayRenderProp}
prefix={prefix}
suffix={[menuVisible ? <UpOutlined /> : <DownOutlined />, suffix]}
focused={menuVisible}
value={value}
onChange={tryChangeValue}
data={mergedData}
// @ts-ignore
invalid={invalid}
appearance={appearance}
/>
)
}
>
{isArrayNonEmpty(treeProps.data) ? (
Expand Down Expand Up @@ -416,6 +425,10 @@ export interface TreeSelectProps
* 选择框后置内容
*/
suffix?: React.ReactNode
/*
* 自定义触发器
*/
customRender?: React.ReactNode | ((option: TreeNodeEventData) => React.ReactNode)
}

if (__DEV__) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/tree-select/stories/custom-render.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const CustomRender = () => {
console.log('TreeSelect onChange: ', checkedIds, selectItem)
}}
customRender={(data) => {
return <Input value={!data ? '' : data.title + ''} placeholder="请选择" />
return <Input value={!data ? '' : data.title + ''} readOnly placeholder="请选择" />
}}
/>
</div>
Expand Down

0 comments on commit 4192796

Please sign in to comment.