Skip to content

Commit aec66d2

Browse files
chore: fix props
1 parent a41e53f commit aec66d2

File tree

1 file changed

+36
-13
lines changed
  • src/components/elements/buttons/button

1 file changed

+36
-13
lines changed

src/components/elements/buttons/button/index.tsx

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,43 @@ const Button = forwardRef<HTMLElement, ButtonProps>(
115115
textTransform !== 'none' && textTransform
116116
)
117117

118+
// Conditionally build props based on element type
119+
const isLinkElement = asValue === 'link' || asValue === 'a'
120+
const isButtonElement = asValue === 'button'
121+
122+
const elementProps: Record<string, any> = {
123+
ref: ref as React.Ref<any>,
124+
'aria-label': ariaLabel,
125+
onClick,
126+
className: buttonClassNames,
127+
style,
128+
...rest
129+
}
130+
131+
// Add link-specific props only for link elements
132+
if (isLinkElement) {
133+
elementProps.href = href
134+
if (external) {
135+
elementProps.target = '_blank'
136+
elementProps.rel = rel || 'noreferrer noopener'
137+
} else if (rel) {
138+
elementProps.rel = rel
139+
}
140+
if (download) {
141+
elementProps.download = download
142+
}
143+
}
144+
145+
// Add button-specific props only for button elements
146+
if (isButtonElement) {
147+
elementProps.disabled = disabled
148+
if (buttonType) {
149+
elementProps.type = buttonType
150+
}
151+
}
152+
118153
return (
119-
<Component
120-
ref={ref as React.Ref<any>}
121-
href={asValue !== 'button' ? href : null}
122-
target={asValue !== 'button' && external ? '_blank' : null}
123-
rel={rel ? rel : external && asValue !== 'button' ? 'noreferrer noopener' : null}
124-
aria-label={ariaLabel}
125-
onClick={onClick}
126-
className={buttonClassNames}
127-
disabled={disabled}
128-
download={as !== 'button' && download ? download : null}
129-
style={style}
130-
{...(asValue === 'button' && { type: buttonType })}
131-
{...rest}>
154+
<Component {...elementProps}>
132155
<span className={clsx(styles['button-holder'], labelBig && styles['label-big'])}>
133156
{children}
134157
{hasSpinner && <Spinner />}

0 commit comments

Comments
 (0)