Skip to content

Commit

Permalink
🎨 add ref to button
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineKM committed Aug 29, 2024
1 parent bce6cea commit 95c1f94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-cameras-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kitchn": patch
---

Add ref to Button
34 changes: 21 additions & 13 deletions packages/kitchn/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ export type ButtonProps = KitchnComponent<
React.ButtonHTMLAttributes<HTMLButtonElement>
>;

const ButtonComponent = styled(
({
as: Component = "button",
children,
loading,
size,
width,
prefix,
suffix,
htmlType,
...props
}: ButtonProps) => {
const ForwardedButton = React.forwardRef<HTMLButtonElement, ButtonProps>(
(
{
as: Component = "button",
children,
loading,
size,
width,
prefix,
suffix,
htmlType,
...props
},
ref: React.ForwardedRef<HTMLButtonElement>,
) => {
const theme = useTheme();
return (
<Component
ref={ref}
aria-label={children ? undefined : "Button"}
aria-busy={loading ? "true" : undefined}
aria-disabled={props.disabled ? "true" : undefined}
Expand Down Expand Up @@ -78,7 +82,11 @@ const ButtonComponent = styled(
</Component>
);
},
)<ButtonProps>`
);

ForwardedButton.displayName = "Button";

const ButtonComponent = styled(ForwardedButton)<ButtonProps>`
position: relative;
display: flex;
align-items: center;
Expand Down

0 comments on commit 95c1f94

Please sign in to comment.