Skip to content
Prev Previous commit
Next Next commit
chore: fix props
  • Loading branch information
michalconsensys committed Sep 1, 2025
commit aec66d2c2c2bee05dff37b4881ede3b7da4a1c41
49 changes: 36 additions & 13 deletions src/components/elements/buttons/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,43 @@ const Button = forwardRef<HTMLElement, ButtonProps>(
textTransform !== 'none' && textTransform
)

// Conditionally build props based on element type
const isLinkElement = asValue === 'link' || asValue === 'a'
const isButtonElement = asValue === 'button'

const elementProps: Record<string, any> = {
ref: ref as React.Ref<any>,
'aria-label': ariaLabel,
onClick,
className: buttonClassNames,
style,
...rest
}

// Add link-specific props only for link elements
if (isLinkElement) {
elementProps.href = href
if (external) {
elementProps.target = '_blank'
elementProps.rel = rel || 'noreferrer noopener'
} else if (rel) {
elementProps.rel = rel
}
if (download) {
elementProps.download = download
}
}

// Add button-specific props only for button elements
if (isButtonElement) {
elementProps.disabled = disabled
if (buttonType) {
elementProps.type = buttonType
}
}

return (
<Component
ref={ref as React.Ref<any>}
href={asValue !== 'button' ? href : null}
target={asValue !== 'button' && external ? '_blank' : null}
rel={rel ? rel : external && asValue !== 'button' ? 'noreferrer noopener' : null}
aria-label={ariaLabel}
onClick={onClick}
className={buttonClassNames}
disabled={disabled}
download={as !== 'button' && download ? download : null}
style={style}
{...(asValue === 'button' && { type: buttonType })}
{...rest}>
<Component {...elementProps}>
<span className={clsx(styles['button-holder'], labelBig && styles['label-big'])}>
{children}
{hasSpinner && <Spinner />}
Expand Down
Loading