-
I wrapped But I am not able to pass the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I modified your example to work right, you need to accept the generics into your component by defining them before your arguments of your component. https://codesandbox.io/s/friendly-microservice-s9wug?file=/src/AutoComplete.tsx import * as React from "react";
import { Box } from "@chakra-ui/react";
import {
Props,
Select as ChakraReactSelect,
GroupBase, // Used for your generic's default value
ChakraStylesConfig
} from "chakra-react-select";
interface ExtraProps {
dataTestId?: string;
// may be some other props
}
// Define your generics after the component's name in order to forward them to the underlying `Select`
export function AutoComplete<
Option,
IsMulti extends boolean = false,
Group extends GroupBase<Option> = GroupBase<Option>
>({
dataTestId,
...rest
}: Props<Option, IsMulti, Group> & ExtraProps): React.ReactElement {
// you need to pass the generics into you `ChakraStylesConfig` type
const autoCompleteStyles: ChakraStylesConfig<Option, IsMulti, Group> = {
container: (provided) => ({
...provided,
borderRadius: "md"
}),
// ....rest of the chakra styles....
valueContainer: (provided) => ({
...provided,
pl: 4,
pr: 0
})
};
return (
<Box data-testid={dataTestId}>
<ChakraReactSelect<Option, IsMulti, Group>
chakraStyles={autoCompleteStyles}
noOptionsMessage={() => "Custom message"}
placeholder="Select an option..."
{...rest}
/>
</Box>
);
} They have a similar example in the |
Beta Was this translation helpful? Give feedback.
I modified your example to work right, you need to accept the generics into your component by defining them before your arguments of your component.
https://codesandbox.io/s/friendly-microservice-s9wug?file=/src/AutoComplete.tsx