Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix button bad children error #1564

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ export const PopoverMenuMobile = ({
<Popover.Root>
<div>
<Popover.Anchor />
<Popover.Trigger>
<button
title="menu"
type="button"
className={cn(
"bg-[#D9D9D9] bg-opacity-30 rounded-full px-4 py-1",
color === "white" ? "text-white" : "text-black"
)}
>
<LuMenu size={32} />
</button>
<Popover.Trigger
title="menu"
type="button"
className={cn(
"bg-[#D9D9D9] bg-opacity-30 rounded-full px-4 py-1",
color === "white" ? "text-white" : "text-black"
)}
>
<LuMenu size={32} />
</Popover.Trigger>
</div>
<Popover.Content
Expand Down
26 changes: 14 additions & 12 deletions frontend/lib/components/ui/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TooltipTrigger,
} from "@radix-ui/react-tooltip";
import { cva, type VariantProps } from "class-variance-authority";
import { ButtonHTMLAttributes, LegacyRef, forwardRef } from "react";
import { ButtonHTMLAttributes, Ref, RefAttributes, forwardRef } from "react";
import { FaSpinner } from "react-icons/fa";

import { cn } from "@/lib/utils";
Expand Down Expand Up @@ -56,22 +56,25 @@ const Button = forwardRef(
}: ButtonProps,
forwardedRef
): JSX.Element => {
const buttonElement = (
<button
className={cn(ButtonVariants({ variant, brightness, className }))}
disabled={isLoading}
{...props}
ref={forwardedRef as LegacyRef<HTMLButtonElement>}
>
const buttonProps: ButtonProps & RefAttributes<HTMLButtonElement> = {
className: cn(ButtonVariants({ variant, brightness, className })),
disabled: isLoading,
...props,
ref: forwardedRef as Ref<HTMLButtonElement> | undefined,
};

const buttonChildren = (
<>
{children} {isLoading && <FaSpinner className="animate-spin" />}
</button>
</>
);
const buttonElement = <button {...buttonProps}>buttonChildren</button>;

if (tooltip !== undefined) {
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger>{buttonElement}</TooltipTrigger>
<TooltipTrigger {...buttonProps}>{buttonChildren}</TooltipTrigger>
<TooltipContent className="bg-gray-100 rounded-md p-1">
{tooltip}
</TooltipContent>
Expand All @@ -80,9 +83,8 @@ const Button = forwardRef(
);
}

return buttonElement;
return <button {...buttonProps}>{buttonChildren}</button>;
}
);

Button.displayName = "Button";
export default Button;
Loading