11import React , { AriaAttributes , ButtonHTMLAttributes , DetailedHTMLProps , RefObject } from 'react' ;
22
3- import isEmpty from 'lodash/isEmpty' ;
4-
53import classNames from 'classnames' ;
64
75import { ColorPalette , Emphasis , Size , Theme } from '@lumx/react' ;
86import { CSS_PREFIX } from '@lumx/react/constants' ;
97import { GenericProps , HasTheme } from '@lumx/react/utils/type' ;
108import { handleBasicClasses } from '@lumx/core/js/utils/className' ;
11- import { renderLink } from '@lumx/react/utils/react/renderLink' ;
129import { forwardRef } from '@lumx/react/utils/react/forwardRef' ;
13- import { useDisableStateProps } from '@lumx/react/utils/disabled/useDisableStateProps' ;
1410import { HasAriaDisabled } from '@lumx/react/utils/type/HasAriaDisabled' ;
11+ import { RawClickable } from '@lumx/react/utils/react/RawClickable' ;
12+ import { useDisableStateProps } from '@lumx/react/utils/disabled' ;
1513
1614type HTMLButtonProps = DetailedHTMLProps < ButtonHTMLAttributes < HTMLButtonElement > , HTMLButtonElement > ;
1715
@@ -107,18 +105,14 @@ export const ButtonRoot = forwardRef<ButtonRootProps, HTMLButtonElement | HTMLAn
107105 color,
108106 emphasis,
109107 hasBackground,
110- href,
111108 isSelected,
112109 isActive,
113110 isFocused,
114111 isHovered,
115112 linkAs,
116- name,
117113 size,
118- target,
119114 theme,
120115 variant,
121- type = 'button' ,
122116 fullWidth,
123117 ...forwardedProps
124118 } = otherProps ;
@@ -139,7 +133,7 @@ export const ButtonRoot = forwardRef<ButtonRootProps, HTMLButtonElement | HTMLAn
139133 color : adaptedColor ,
140134 emphasis,
141135 isSelected,
142- isDisabled : isAnyDisabled ,
136+ isDisabled : props . isDisabled || props [ 'aria-disabled' ] ,
143137 isActive,
144138 isFocused,
145139 isHovered,
@@ -151,42 +145,18 @@ export const ButtonRoot = forwardRef<ButtonRootProps, HTMLButtonElement | HTMLAn
151145 } ) ,
152146 ) ;
153147
154- /**
155- * If the linkAs prop is used, we use the linkAs component instead of a <button>.
156- * If there is an href attribute, we display an <a> instead of a <button>.
157- *
158- * However, in any case, if the component is disabled, we returned a <button> since disabled is not compatible with <a>.
159- */
160- if ( ( linkAs || ! isEmpty ( props . href ) ) && ! isAnyDisabled ) {
161- return renderLink (
162- {
163- linkAs,
164- ...forwardedProps ,
165- 'aria-label' : ariaLabel ,
166- href,
167- target,
168- className : buttonClassName ,
169- ref : ref as RefObject < HTMLAnchorElement > ,
170- } ,
171- children ,
172- ) ;
173- }
174148 return (
175- < button
149+ < RawClickable
150+ as = { linkAs || ( forwardedProps . href ? 'a' : 'button' ) }
176151 { ...forwardedProps }
177152 { ...disabledStateProps }
178153 aria-disabled = { isAnyDisabled }
179154 aria-label = { ariaLabel }
180155 ref = { ref as RefObject < HTMLButtonElement > }
181156 className = { buttonClassName }
182- name = { name }
183- type = {
184- // eslint-disable-next-line react/button-has-type
185- type
186- }
187157 >
188158 { children }
189- </ button >
159+ </ RawClickable >
190160 ) ;
191161} ) ;
192162ButtonRoot . displayName = COMPONENT_NAME ;
0 commit comments