Skip to content

Commit 115e28b

Browse files
committed
Fix the useSize hook
1 parent 9e158d1 commit 115e28b

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/utils.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const cleanCommonProps = <
4343
return { ...innerProps };
4444
};
4545

46-
/** A typeguard to ensure the default size on the Input component is valid. */
46+
/** A type guard to ensure the default size on the Input component is valid. */
4747
const isSize = (size: unknown): size is Size => {
4848
const isString = typeof size === "string";
4949
return isString && ["sm", "md", "lg"].includes(size);
@@ -70,17 +70,16 @@ const getDefaultSize = (size: unknown): Size => {
7070
export const useSize = (size: SizeProp | undefined): Size => {
7171
const chakraContext = useChakraContext();
7272
const defaultSize = getDefaultSize(
73-
// TODO: This doesn't seem to work as expected
74-
chakraContext.getSlotRecipe("select")?.defaultSize
73+
chakraContext.getSlotRecipe("select")?.defaultVariants?.size
7574
);
7675

7776
// Ensure that the size used is one of the options, either `sm`, `md`, or `lg`
78-
const definedSize = size ?? defaultSize;
7977
// Or, if a breakpoint is passed, get the size based on the current screen size
80-
return (
81-
// @ts-expect-error - I'm not sure why this is throwing an error - TODO: Figure this out
82-
useBreakpointValue(definedSize, { fallback: defaultSize }) ?? defaultSize
83-
);
78+
const responsiveSize = (typeof size === "string" ? [size] : size) ?? [
79+
defaultSize,
80+
];
81+
82+
return useBreakpointValue(responsiveSize) ?? defaultSize;
8483
};
8584

8685
export function useColorMode() {

0 commit comments

Comments
 (0)