From d8d70fb6fca3dd463f9eda31b99d55bb9dd0041b Mon Sep 17 00:00:00 2001 From: Diego Andai Date: Wed, 13 Sep 2023 14:16:08 -0300 Subject: [PATCH] Port change to material-next ButtonBase --- .../mui-material-next/src/ButtonBase/ButtonBase.tsx | 13 +++++++++---- .../src/ButtonBase/ButtonBase.types.ts | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/mui-material-next/src/ButtonBase/ButtonBase.tsx b/packages/mui-material-next/src/ButtonBase/ButtonBase.tsx index de46813447ad93..6fc4b70df50541 100644 --- a/packages/mui-material-next/src/ButtonBase/ButtonBase.tsx +++ b/packages/mui-material-next/src/ButtonBase/ButtonBase.tsx @@ -42,7 +42,7 @@ export const ButtonBaseRoot = styled('button', { slot: 'Root', shouldForwardProp: (prop) => rootShouldForwardProp(prop) && prop !== 'touchRippleRef', overridesResolver: (props, styles) => styles.root, -})({ +})<{ ownerState: ButtonBaseOwnerState }>(({ ownerState }) => ({ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', @@ -57,7 +57,9 @@ export const ButtonBaseRoot = styled('button', { borderRadius: 0, padding: 0, // Remove the padding in Firefox cursor: 'pointer', - userSelect: 'none', + '&:active': { + userSelect: 'none', + }, verticalAlign: 'middle', MozAppearance: 'none', // Reset WebkitAppearance: 'none', // Reset @@ -68,13 +70,15 @@ export const ButtonBaseRoot = styled('button', { borderStyle: 'none', // Remove Firefox dotted outline. }, [`&.${buttonBaseClasses.disabled}`]: { - pointerEvents: 'none', // Disable link interactions + ...(!ownerState.isButton && { + pointerEvents: 'none', // Disable link interactions + }), cursor: 'default', }, '@media print': { colorAdjust: 'exact', }, -}) as React.ElementType; +})) as React.ElementType; /** * `ButtonBase` contains as few styles as possible. @@ -156,6 +160,7 @@ const ButtonBase = React.forwardRef(function ButtonBase< disableTouchRipple, focusVisible, active, + isButton: ComponentProp === 'button', }; const classes = useUtilityClasses(ownerState); diff --git a/packages/mui-material-next/src/ButtonBase/ButtonBase.types.ts b/packages/mui-material-next/src/ButtonBase/ButtonBase.types.ts index 1ed0777f27ecff..679fbfe4f5100b 100644 --- a/packages/mui-material-next/src/ButtonBase/ButtonBase.types.ts +++ b/packages/mui-material-next/src/ButtonBase/ButtonBase.types.ts @@ -126,6 +126,10 @@ export type ButtonBaseProps< }; export interface ButtonBaseOwnerState extends ButtonBaseProps { + /** + * If `true`, the DOM element is button. + */ + isButton: boolean; /** * If `true`, the button is active. */