Skip to content

Commit

Permalink
feat: add button ref
Browse files Browse the repository at this point in the history
  • Loading branch information
abelflopes committed May 16, 2024
1 parent efd0a4f commit 7db6790
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/components/button/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface ButtonProps<T extends HTMLTag = "button">
* This can be any valid React node, allowing integration of icons or custom SVG components.
*/
icon?: React.ReactNode;
/** Ref for the root element */
rootRef?: React.ForwardedRef<HTMLButtonElement>;
}

/**
Expand All @@ -40,6 +42,7 @@ export const Button = <T extends HTMLTag>({
icon,
children,
className,
rootRef,
...otherProps
}: Readonly<ButtonProps<T>>): React.ReactElement => {
const isIconOnly = useMemo(
Expand All @@ -59,7 +62,13 @@ export const Button = <T extends HTMLTag>({
return (
<PolymorphicComponent
as={as}
fallback={["button", otherProps]}
fallback={[
"button",
{
ref: rootRef,
...otherProps,
},
]}
commonProps={{
className: classNames(
styles.root,
Expand Down

0 comments on commit 7db6790

Please sign in to comment.