Skip to content

Commit

Permalink
fix: button component with asChild (#162)
Browse files Browse the repository at this point in the history
* fix: `asChild` prop for button

* fix: remove ts-expect-error for href button
  • Loading branch information
lawvs authored Jul 28, 2024
1 parent 3681810 commit 984d2de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/renderer/src/components/ui/button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Slot } from "@radix-ui/react-slot"
import { Slot, Slottable } from "@radix-ui/react-slot"
import { stopPropagation } from "@renderer/lib/dom"
import { cn } from "@renderer/lib/utils"
import type { VariantProps } from "class-variance-authority"
Expand Down Expand Up @@ -55,7 +55,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
{isLoading && (
<i className="i-mgc-loading-3-cute-re mr-2 animate-spin" />
)}
{props.children}
<Slottable>{props.children}</Slottable>
</Comp>
)
},
Expand All @@ -72,6 +72,7 @@ interface ActionButtonProps {
active?: boolean
shortcut?: string
as?: keyof React.JSX.IntrinsicElements
asChild?: boolean
}

export const ActionButton = React.forwardRef<
Expand All @@ -89,6 +90,7 @@ export const ActionButton = React.forwardRef<
active,
shortcut,
as,
asChild,
},
ref,
) => {
Expand All @@ -107,6 +109,7 @@ export const ActionButton = React.forwardRef<
<TooltipTrigger asChild>
<Button
as={as}
asChild={asChild}
ref={buttonRef}
// @see https://github.com/radix-ui/primitives/issues/2248#issuecomment-2147056904
onFocusCapture={stopPropagation}
Expand Down
13 changes: 6 additions & 7 deletions src/renderer/src/modules/settings/tabs/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,16 @@ export const SettingAbout = () => (
<div className="mt-2 flex flex-wrap gap-2">
{SocialMediaLinks.map((link) => (
<Button
as="a"
asChild
key={link.url}
variant="outline"
className="flex flex-1 cursor-pointer items-center gap-2"
// @ts-expect-error
href={link.url}
target="_blank"
rel="noreferrer"

>
<i className={link.icon} />
{link.label}
<a href={link.url} target="_blank" rel="noreferrer">
<i className={link.icon} />
{link.label}
</a>
</Button>
))}
</div>
Expand Down

0 comments on commit 984d2de

Please sign in to comment.