Skip to content

Commit

Permalink
fix: remove ref passing in withRootProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
malangcat committed Jan 16, 2025
1 parent d7e1f2a commit b42abc9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
23 changes: 10 additions & 13 deletions packages/react/src/components/HelpBubble/HelpBubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@ const withStateProps = createWithStateProps([usePopoverContext]);

export interface HelpBubbleRootProps extends HelpBubbleVariantProps, PopoverPrimitive.RootProps {}

export const HelpBubbleRoot = withRootProvider<HTMLDivElement, HelpBubbleRootProps>(
PopoverPrimitive.Root,
{
defaultProps: {
placement: "top",
gutter: 4,
overflowPadding: 16,
arrowPadding: 14,
flip: true,
slide: true,
strategy: "absolute",
},
export const HelpBubbleRoot = withRootProvider<HelpBubbleRootProps>(PopoverPrimitive.Root, {
defaultProps: {
placement: "top",
gutter: 4,
overflowPadding: 16,
arrowPadding: 14,
flip: true,
slide: true,
strategy: "absolute",
},
);
});

////////////////////////////////////////////////////////////////////////////////////

Expand Down
10 changes: 5 additions & 5 deletions packages/react/src/utils/createStyleContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ export function createStyleContext<
return useContext(PropsContext);
}

const withRootProvider = <T, P>(
const withRootProvider = <P,>(
Component: React.ElementType<any>,
options?: {
defaultProps?: Partial<P>;
},
): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>> => {
): React.ForwardRefExoticComponent<React.PropsWithoutRef<P>> => {
const { defaultProps } = options ?? {};

const StyledComponent = forwardRef<any, any>((innerProps, ref) => {
const StyledComponent = (innerProps: any) => {
const props = { ...(defaultProps ?? {}), ...useProps(), ...innerProps } as Props &
React.HTMLAttributes<HTMLElement>;
const [variantProps, otherProps] = recipe.splitVariantProps(props);
const classNames = recipe(variantProps); // TODO: should we memoize this?

return (
<ClassNamesProvider value={classNames}>
<Component ref={ref} {...otherProps} />
<Component {...otherProps} />
</ClassNamesProvider>
);
});
};

// @ts-ignore
StyledComponent.displayName = Component.displayName || Component.name;
Expand Down

0 comments on commit b42abc9

Please sign in to comment.