From 763a4b53c0b6fd0792919194368ece1995bb014e Mon Sep 17 00:00:00 2001 From: Diego Andai Date: Wed, 23 Aug 2023 11:51:38 -0400 Subject: [PATCH] Experiment 2 (disabled non-button not working) --- .../experiments/material/button-select.tsx | 120 ++++++++++-------- .../mui-material/src/ButtonBase/ButtonBase.js | 73 ++++++----- 2 files changed, 105 insertions(+), 88 deletions(-) diff --git a/docs/pages/experiments/material/button-select.tsx b/docs/pages/experiments/material/button-select.tsx index 76585aacb9cb8b..dd270028b7f32b 100644 --- a/docs/pages/experiments/material/button-select.tsx +++ b/docs/pages/experiments/material/button-select.tsx @@ -6,8 +6,10 @@ import { extendTheme as joyExtendTheme, } from '@mui/joy'; import { + FormControlLabel, Button as MaterialUIButton, Experimental_CssVarsProvider as MaterialUICssVarsProvider, + Switch, experimental_extendTheme as materialUIExtendTheme, } from '@mui/material'; import { Stack } from '@mui/system'; @@ -21,34 +23,38 @@ function createHandlers(name: string) { } export default function App() { + const [disabled, setDisabled] = React.useState(false); + return ( - - - - Enabled native button - - - - Disabled native button - + + + + setDisabled((prev) => !prev)} />} + label="Toggle disabled" + /> - - Native anchor - - Anchor - - - - Native div -
Button
-
-
+ + + + Native button + + + + Native anchor + + Anchor + + + + Native div +
Button
+
+
- {/* + {/* Enabled Base UI button Button @@ -104,36 +110,42 @@ export default function App() { */} - - - - Enabled Material UI button - Button - - - Disabled Material UI button - - Button - - - - Enabled Material UI button as div - - Button - - - - Disabled Material UI button as div - - Button - + + + Material UI button + + Button + + + + Material UI button link + + Button + + + + Material UI button as div + + Button + + - + - +
); } diff --git a/packages/mui-material/src/ButtonBase/ButtonBase.js b/packages/mui-material/src/ButtonBase/ButtonBase.js index 27309d18d2de8b..787ca8251e7a39 100644 --- a/packages/mui-material/src/ButtonBase/ButtonBase.js +++ b/packages/mui-material/src/ButtonBase/ButtonBase.js @@ -32,42 +32,46 @@ export const ButtonBaseRoot = styled('button', { name: 'MuiButtonBase', slot: 'Root', overridesResolver: (props, styles) => styles.root, -})({ - display: 'inline-flex', - alignItems: 'center', - justifyContent: 'center', - position: 'relative', - boxSizing: 'border-box', - WebkitTapHighlightColor: 'transparent', - backgroundColor: 'transparent', // Reset default value - // We disable the focus ring for mouse, touch and keyboard users. - outline: 0, - border: 0, - margin: 0, // Remove the margin in Safari - borderRadius: 0, - padding: 0, // Remove the padding in Firefox - cursor: 'pointer', - verticalAlign: 'middle', - MozAppearance: 'none', // Reset - WebkitAppearance: 'none', // Reset - textDecoration: 'none', - // So we take precedent over the style of a native element. - color: 'inherit', - '&:active': { - userSelect: 'none', - }, - '&::-moz-focus-inner': { - borderStyle: 'none', // Remove Firefox dotted outline. - }, - [`&.${buttonBaseClasses.disabled}`]: { - cursor: 'default', +})(({ ownerState }) => { + const { isButton } = ownerState; + + return { + display: 'inline-flex', + alignItems: 'center', + justifyContent: 'center', + position: 'relative', + boxSizing: 'border-box', + WebkitTapHighlightColor: 'transparent', + backgroundColor: 'transparent', // Reset default value + // We disable the focus ring for mouse, touch and keyboard users. + outline: 0, + border: 0, + margin: 0, // Remove the margin in Safari + borderRadius: 0, + padding: 0, // Remove the padding in Firefox + cursor: 'pointer', + verticalAlign: 'middle', + MozAppearance: 'none', // Reset + WebkitAppearance: 'none', // Reset + textDecoration: 'none', + // So we take precedent over the style of a native element. + color: 'inherit', '&:active': { - pointerEvents: 'none', // Disable link interactions + userSelect: 'none', }, - }, - '@media print': { - colorAdjust: 'exact', - }, + '&::-moz-focus-inner': { + borderStyle: 'none', // Remove Firefox dotted outline. + }, + [`&.${buttonBaseClasses.disabled}`]: { + cursor: 'default', + ...(!isButton && { + pointerEvents: 'none', // Disable link interactions + }), + }, + '@media print': { + colorAdjust: 'exact', + }, + }; }); /** @@ -332,6 +336,7 @@ const ButtonBase = React.forwardRef(function ButtonBase(inProps, ref) { ...props, centerRipple, component, + isButton: ComponentProp === 'button', disabled, disableRipple, disableTouchRipple,