Skip to content

Commit

Permalink
Decrease scope of change
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai committed Oct 6, 2023
1 parent d8d70fb commit a4016f1
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 80 deletions.
125 changes: 64 additions & 61 deletions docs/pages/experiments/material/button-select.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
import * as React from 'react';
import {
CssBaseline,
FormControlLabel,
Button as MaterialUIButton,
Experimental_CssVarsProvider as MaterialUICssVarsProvider,
Expand All @@ -19,71 +20,73 @@ export default function App() {
const [disabled, setDisabled] = React.useState(false);

return (
<MaterialUICssVarsProvider theme={materialUIExtendTheme({})}>
<Stack gap={12} alignItems="center" sx={{ my: 6 }}>
<Stack>
<FormControlLabel
control={<Switch checked={disabled} onChange={() => setDisabled((prev) => !prev)} />}
label="Toggle disabled"
/>
</Stack>
<Stack direction="row" justifyContent="space-around" sx={{ width: '80vw' }}>
<Stack gap={3}>
<Stack alignItems="flex-start">
<span>Native button</span>
<button type="button" disabled={disabled} {...createHandlers('Native button')}>
Button
</button>
</Stack>
<Stack alignItems="flex-start">
<span>Native anchor</span>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a href="#" {...createHandlers('Native anchor')}>
Anchor
</a>
</Stack>
<Stack alignItems="flex-start">
<span>Native div</span>
<div {...createHandlers('Div')}>Button</div>
</Stack>
<CssBaseline>
<MaterialUICssVarsProvider theme={materialUIExtendTheme({})}>
<Stack gap={12} alignItems="center" sx={{ my: 6 }}>
<Stack>
<FormControlLabel
control={<Switch checked={disabled} onChange={() => setDisabled((prev) => !prev)} />}
label="Toggle disabled"
/>
</Stack>

<Stack gap={3}>
<Stack alignItems="flex-start">
<span>Material UI button</span>
<MaterialUIButton
variant="contained"
disabled={disabled}
{...createHandlers('Material UI button')}
>
Button
</MaterialUIButton>
</Stack>
<Stack alignItems="flex-start">
<span>Material UI button link</span>
<MaterialUIButton
variant="contained"
disabled={disabled}
href="#"
{...createHandlers('Material UI button link')}
>
Button
</MaterialUIButton>
<Stack direction="row" justifyContent="space-around" sx={{ width: '80vw' }}>
<Stack gap={3}>
<Stack alignItems="flex-start">
<span>Native button</span>
<button type="button" disabled={disabled} {...createHandlers('Native button')}>
Button
</button>
</Stack>
<Stack alignItems="flex-start">
<span>Native anchor</span>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a href="#" {...createHandlers('Native anchor')}>
Anchor
</a>
</Stack>
<Stack alignItems="flex-start">
<span>Native div</span>
<div {...createHandlers('Div')}>Button</div>
</Stack>
</Stack>
<Stack alignItems="flex-start">
<span>Material UI button as div</span>
<MaterialUIButton
variant="contained"
component="div"
disabled={disabled}
{...createHandlers('Material UI button as div')}
>
Button
</MaterialUIButton>

<Stack gap={3}>
<Stack alignItems="flex-start">
<span>Material UI button</span>
<MaterialUIButton
variant="contained"
disabled={disabled}
{...createHandlers('Material UI button')}
>
Button
</MaterialUIButton>
</Stack>
<Stack alignItems="flex-start">
<span>Material UI button link</span>
<MaterialUIButton
variant="contained"
disabled={disabled}
href="#"
{...createHandlers('Material UI button link')}
>
Button
</MaterialUIButton>
</Stack>
<Stack alignItems="flex-start">
<span>Material UI button as div</span>
<MaterialUIButton
variant="contained"
component="div"
disabled={disabled}
{...createHandlers('Material UI button as div')}
>
Button
</MaterialUIButton>
</Stack>
</Stack>
</Stack>
</Stack>
</Stack>
</MaterialUICssVarsProvider>
</MaterialUICssVarsProvider>
</CssBaseline>
);
}
15 changes: 8 additions & 7 deletions packages/mui-material-next/src/ButtonBase/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -57,7 +57,11 @@ export const ButtonBaseRoot = styled('button', {
borderRadius: 0,
padding: 0, // Remove the padding in Firefox
cursor: 'pointer',
'&:active': {
// userSelect: 'text' to overcome Firefox's default behavior
userSelect: 'text',
// only apply userSelect: none when focused so
// selection from dragging from outside the element is possible
'&:focus': {
userSelect: 'none',
},
verticalAlign: 'middle',
Expand All @@ -70,15 +74,13 @@ export const ButtonBaseRoot = styled('button', {
borderStyle: 'none', // Remove Firefox dotted outline.
},
[`&.${buttonBaseClasses.disabled}`]: {
...(!ownerState.isButton && {
pointerEvents: 'none', // Disable link interactions
}),
pointerEvents: 'none', // Disable interactions
cursor: 'default',
},
'@media print': {
colorAdjust: 'exact',
},
})) as React.ElementType<any>;
}) as React.ElementType<any>;

/**
* `ButtonBase` contains as few styles as possible.
Expand Down Expand Up @@ -160,7 +162,6 @@ const ButtonBase = React.forwardRef(function ButtonBase<
disableTouchRipple,
focusVisible,
active,
isButton: ComponentProp === 'button',
};

const classes = useUtilityClasses(ownerState);
Expand Down
4 changes: 0 additions & 4 deletions packages/mui-material-next/src/ButtonBase/ButtonBase.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ export type ButtonBaseProps<
};

export interface ButtonBaseOwnerState extends ButtonBaseProps {
/**
* If `true`, the DOM element is button.
*/
isButton: boolean;
/**
* If `true`, the button is active.
*/
Expand Down
15 changes: 8 additions & 7 deletions packages/mui-material/src/ButtonBase/ButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const ButtonBaseRoot = styled('button', {
name: 'MuiButtonBase',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})(({ ownerState }) => ({
})({
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
Expand All @@ -53,22 +53,24 @@ export const ButtonBaseRoot = styled('button', {
textDecoration: 'none',
// So we take precedent over the style of a native <a /> element.
color: 'inherit',
'&:active': {
// userSelect: 'text' to overcome Firefox's default behavior
userSelect: 'text',
// Only apply userSelect: none when focused so
// selection from dragging from outside the element is possible
'&:focus': {
userSelect: 'none',
},
'&::-moz-focus-inner': {
borderStyle: 'none', // Remove Firefox dotted outline.
},
[`&.${buttonBaseClasses.disabled}`]: {
pointerEvents: 'none', // Disable interactions
cursor: 'default',
...(!ownerState.isButton && {
pointerEvents: 'none', // Disable link interactions
}),
},
'@media print': {
colorAdjust: 'exact',
},
}));
});

/**
* `ButtonBase` contains as few styles as possible.
Expand Down Expand Up @@ -332,7 +334,6 @@ const ButtonBase = React.forwardRef(function ButtonBase(inProps, ref) {
...props,
centerRipple,
component,
isButton: ComponentProp === 'button',
disabled,
disableRipple,
disableTouchRipple,
Expand Down
6 changes: 5 additions & 1 deletion packages/mui-material/src/Link/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ const LinkRoot = styled(Typography, {
textDecorationColor: 'inherit',
},
}),
'&:active': {
// userSelect: 'text' to overcome Firefox's default behavior
userSelect: 'text',
// Only apply userSelect: none when focused so
// selection from dragging from outside the element is possible
'&:focus': {
userSelect: 'none',
},
// Same reset as ButtonBase.root
Expand Down

0 comments on commit a4016f1

Please sign in to comment.