@@ -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