Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Jul 10, 2024
1 parent 994169e commit 5d04231
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 42 deletions.
1 change: 0 additions & 1 deletion src/Fields/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export function SelectField<
// Makes the allowClear method able to actually affect the form value
// See https://react-hook-form.com/api/usecontroller/controller
// > Calling onChange with undefined is not valid. You should use null or the empty string as your default/cleared value instead.
// @ts-expect-error error make no sense to me and i spent to much time on it
onChange={(value) => onChange(value ?? null)}
{...component}
/>
Expand Down
82 changes: 41 additions & 41 deletions src/Select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { BaseSelectRef } from 'rc-select';
import React, {
ForwardedRef,
forwardRef,
ForwardRefExoticComponent,
ReactElement,
ReactNode,
RefAttributes,
useCallback,
} from 'react';
Expand Down Expand Up @@ -46,49 +46,49 @@ const StyledDropdown = styled.div`
}
`;

type SelectType = ForwardRefExoticComponent<
SelectProps<unknown, BaseOptionType | DefaultOptionType> &
RefAttributes<BaseSelectRef>
> & { Option: typeof AntdSelect.Option; OptGroup: typeof AntdSelect.OptGroup };
function SelectInner<
ValueType = unknown,
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,
>(
{
children,
dropdownRender,
onChange,
...props
}: SelectProps<ValueType, OptionType>,
ref: ForwardedRef<BaseSelectRef>,
) {
const styledDropdownRender = useCallback(
(menu: ReactElement) => (
<StyledDropdown>
{dropdownRender ? dropdownRender(menu) : menu}
</StyledDropdown>
),
[dropdownRender],
);

const InternalSelect = forwardRef<
return (
<StyledSelect<ValueType, OptionType>
ref={ref}
{...props}
dropdownRender={styledDropdownRender}
>
{children}
</StyledSelect>
);
}

export const Select = forwardRef<
BaseSelectRef,
SelectProps<unknown, BaseOptionType | DefaultOptionType>
>(SelectInner) as unknown as (<
TValue = unknown,
TOption extends BaseOptionType | DefaultOptionType = DefaultOptionType,
>(
<
ValueType = unknown,
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,
>(
{
children,
dropdownRender,
onChange,
...props
}: SelectProps<ValueType, OptionType>,
ref: ForwardedRef<BaseSelectRef>,
) => {
const styledDropdownRender = useCallback(
(menu: ReactElement) => (
<StyledDropdown>
{dropdownRender ? dropdownRender(menu) : menu}
</StyledDropdown>
),
[dropdownRender],
);

return (
<StyledSelect<ValueType, OptionType>
ref={ref}
{...props}
dropdownRender={styledDropdownRender}
>
{children}
</StyledSelect>
);
},
);
InternalSelect.displayName = 'Select';

export const Select = InternalSelect as SelectType;
props: SelectProps<TValue, TOption> & RefAttributes<BaseSelectRef>,
) => ReactNode) & {
Option: typeof AntdSelect.Option;
OptGroup: typeof AntdSelect.OptGroup;
};
Select.Option = AntdSelect.Option;
Select.OptGroup = AntdSelect.OptGroup;

0 comments on commit 5d04231

Please sign in to comment.