Skip to content

Commit e81f2f5

Browse files
committed
chore: adjust logic
1 parent 36220d3 commit e81f2f5

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/BaseSelect/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,9 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
908908
// );
909909
// }
910910

911-
const { root: RootComponent } = useComponents(components);
911+
const mergedComponents = useComponents(components);
912+
const { root: RootComponent } = mergedComponents;
913+
912914
renderNode = (
913915
<RootComponent
914916
{...restProps}
@@ -944,6 +946,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
944946
tokenWithEnter={tokenWithEnter}
945947
// Open
946948
onMouseDown={onInternalMouseDown}
949+
// Components
950+
components={mergedComponents}
947951
/>
948952
);
949953

src/hooks/useComponents.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@ import * as React from 'react';
22
import SelectInput, { type SelectInputProps } from '../SelectInput';
33

44
export interface ComponentsConfig {
5-
root?: React.ComponentType<any>;
6-
input?: React.ComponentType<any>;
5+
root?: React.ComponentType<any> | string;
6+
input?:
7+
| React.ComponentType<
8+
| React.TextareaHTMLAttributes<HTMLTextAreaElement>
9+
| React.InputHTMLAttributes<HTMLInputElement>
10+
>
11+
| string;
712
}
813

9-
export interface ReturnType {
10-
root: React.ComponentType<SelectInputProps> | string;
11-
input: React.ComponentType<any> | string;
14+
export interface FilledComponentsConfig {
15+
root: React.ComponentType<SelectInputProps>;
16+
input: React.ComponentType<
17+
React.TextareaHTMLAttributes<HTMLTextAreaElement> | React.InputHTMLAttributes<HTMLInputElement>
18+
>;
1219
}
1320

14-
export default function useComponents(components?: ComponentsConfig): ReturnType {
21+
export default function useComponents(components?: ComponentsConfig) {
1522
return React.useMemo(() => {
1623
const { root: RootComponent = SelectInput, input: InputComponent = 'input' } = components || {};
1724

18-
return { root: RootComponent, input: InputComponent };
25+
return { root: RootComponent, input: InputComponent } as FilledComponentsConfig;
1926
}, [components]);
2027
}

0 commit comments

Comments
 (0)