Skip to content

Commit 9b29f64

Browse files
committed
Merge branch '@invertase/v7-development' of https://github.com/firebase/firebaseui-web into v7-pnpm-workspace-catalogs
2 parents 1bd9594 + 2c22254 commit 9b29f64

File tree

4 files changed

+91
-61
lines changed

4 files changed

+91
-61
lines changed

packages/firebaseui-react/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"react-dom": "catalog:peerDependencies"
3939
},
4040
"dependencies": {
41-
"@nanostores/react": "^1.0.0",
41+
"@nanostores/react": "^0.8.4",
42+
"@radix-ui/react-slot": "^1.2.3",
4243
"@tanstack/react-form": "^0.41.3",
4344
"clsx": "^2.1.1",
4445
"tailwind-merge": "^3.0.1",

packages/firebaseui-react/src/components/button.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { ButtonHTMLAttributes } from "react";
18+
import { Slot } from "@radix-ui/react-slot"
1819
import { cn } from "~/utils/cn";
1920

2021
const buttonVariants = {
@@ -26,21 +27,21 @@ type ButtonVariant = keyof typeof buttonVariants;
2627

2728
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
2829
variant?: ButtonVariant;
30+
asChild?: boolean;
2931
}
3032

3133
export function Button({
32-
children,
3334
className,
3435
variant = "primary",
36+
asChild,
3537
...props
3638
}: ButtonProps) {
39+
const Comp = asChild ? Slot : "button";
40+
3741
return (
38-
<button
39-
type="button"
42+
<Comp
4043
className={cn(buttonVariants[variant], className)}
4144
{...props}
42-
>
43-
{children}
44-
</button>
45+
/>
4546
);
4647
}

packages/firebaseui-react/tests/unit/components/button.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,28 @@ describe("Button Component", () => {
6262

6363
expect(button).toBeDisabled();
6464
});
65+
66+
it("renders as a Slot component when asChild is true", () => {
67+
render(
68+
<Button asChild>
69+
<a href="/test">Link Button</a>
70+
</Button>
71+
);
72+
const link = screen.getByRole("link", { name: /link button/i });
73+
74+
expect(link).toBeInTheDocument();
75+
expect(link).toHaveClass("fui-button");
76+
expect(link.tagName).toBe("A");
77+
expect(link).toHaveAttribute("href", "/test");
78+
});
79+
80+
it("renders as a button element when asChild is false or undefined", () => {
81+
const { rerender } = render(<Button>Regular Button</Button>);
82+
let button = screen.getByRole("button", { name: /regular button/i });
83+
expect(button.tagName).toBe("BUTTON");
84+
85+
rerender(<Button asChild={false}>Regular Button</Button>);
86+
button = screen.getByRole("button", { name: /regular button/i });
87+
expect(button.tagName).toBe("BUTTON");
88+
});
6589
});

pnpm-lock.yaml

Lines changed: 58 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)