Skip to content

Commit

Permalink
Fix: React compiler error on button. (#61958)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
  • Loading branch information
jorgefilipecosta and jorgefilipecosta authored May 29, 2024
1 parent 5018e24 commit c4e00ff
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ export function UnforwardedButton(
const anchorProps: ComponentPropsWithoutRef< 'a' > =
Tag === 'a' ? { href, target } : {};

const disableEventProps: {
[ key: string ]: ( event: MouseEvent ) => void;
} = {};
if ( disabled && isFocusable ) {
// In this case, the button will be disabled, but still focusable and
// perceivable by screen reader users.
buttonProps[ 'aria-disabled' ] = true;
anchorProps[ 'aria-disabled' ] = true;

for ( const disabledEvent of disabledEventsOnDisabledButton ) {
additionalProps[ disabledEvent ] = ( event: MouseEvent ) => {
disableEventProps[ disabledEvent ] = ( event: MouseEvent ) => {
if ( event ) {
event.stopPropagation();
event.preventDefault();
Expand Down Expand Up @@ -234,6 +236,7 @@ export function UnforwardedButton(
<a
{ ...anchorProps }
{ ...( additionalProps as HTMLAttributes< HTMLAnchorElement > ) }
{ ...disableEventProps }
{ ...commonProps }
>
{ elementChildren }
Expand All @@ -242,6 +245,7 @@ export function UnforwardedButton(
<button
{ ...buttonProps }
{ ...( additionalProps as HTMLAttributes< HTMLButtonElement > ) }
{ ...disableEventProps }
{ ...commonProps }
>
{ elementChildren }
Expand Down

0 comments on commit c4e00ff

Please sign in to comment.