Skip to content

Commit

Permalink
[Snackbar] Remove RTL direction specific logic (#32808)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaarichter committed Jun 8, 2022
1 parent 57d68d9 commit 96f5a72
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 29 deletions.
37 changes: 8 additions & 29 deletions packages/mui-material/src/Snackbar/Snackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,9 @@ const SnackbarRoot = styled('div', {
},
})(({ theme, ownerState }) => {
const center = {
...(!ownerState.isRtl && {
left: '50%',
right: 'auto',
transform: 'translateX(-50%)',
}),
...(ownerState.isRtl && {
right: '50%',
left: 'auto',
transform: 'translateX(50%)',
}),
left: '50%',
right: 'auto',
transform: 'translateX(-50%)',
};

return {
Expand All @@ -69,24 +62,12 @@ const SnackbarRoot = styled('div', {
...(ownerState.anchorOrigin.vertical === 'top' ? { top: 24 } : { bottom: 24 }),
...(ownerState.anchorOrigin.horizontal === 'center' && center),
...(ownerState.anchorOrigin.horizontal === 'left' && {
...(!ownerState.isRtl && {
left: 24,
right: 'auto',
}),
...(ownerState.isRtl && {
right: 24,
left: 'auto',
}),
left: 24,
right: 'auto',
}),
...(ownerState.anchorOrigin.horizontal === 'right' && {
...(!ownerState.isRtl && {
right: 24,
left: 'auto',
}),
...(ownerState.isRtl && {
left: 24,
right: 'auto',
}),
right: 24,
left: 'auto',
}),
},
};
Expand Down Expand Up @@ -123,9 +104,7 @@ const Snackbar = React.forwardRef(function Snackbar(inProps, ref) {
...other
} = props;

const isRtl = theme.direction === 'rtl';

const ownerState = { ...props, anchorOrigin: { vertical, horizontal }, isRtl };
const ownerState = { ...props, anchorOrigin: { vertical, horizontal } };
const classes = useUtilityClasses(ownerState);

const timerAutoHide = React.useRef();
Expand Down
22 changes: 22 additions & 0 deletions test/regressions/fixtures/Snackbar/PositionedSnackbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Snackbar from '@mui/material/Snackbar';

export default function PositionedSnackbar() {
return (
<Box dir="ltr" sx={{ width: window?.innerWidth, height: '100vh' }}>
<Snackbar
key="left"
anchorOrigin={{ horizontal: 'left', vertical: 'bottom' }}
message="Snackbar should show left (LTR)"
open
/>
<Snackbar
key="right"
anchorOrigin={{ horizontal: 'right', vertical: 'top' }}
message="Snackbar should show right (LTR)"
open
/>
</Box>
);
}
43 changes: 43 additions & 0 deletions test/regressions/fixtures/Snackbar/PositionedSnackbarRtl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { prefixer } from 'stylis';
import rtlPlugin from 'stylis-plugin-rtl';
import rtlPluginSc from 'stylis-plugin-rtl-sc';
import { StyleSheetManager } from 'styled-components';
import { CacheProvider } from '@emotion/react';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import createCache from '@emotion/cache';
import Snackbar from '@mui/material/Snackbar';

// Create rtl cache
const cacheRtl = createCache({
key: 'muirtl',
stylisPlugins: [prefixer, rtlPlugin],
});

const theme = createTheme({ direction: 'rtl' });

export default function PositionedSnackbar() {
return (
<StyleSheetManager stylisPlugins={[rtlPluginSc]}>
<CacheProvider value={cacheRtl}>
<ThemeProvider theme={theme}>
<Box dir="rtl" sx={{ width: window?.innerWidth, height: '100vh' }}>
<Snackbar
key="left"
anchorOrigin={{ horizontal: 'left', vertical: 'bottom' }}
message="Snackbar should show right (RTL)"
open
/>
<Snackbar
key="right"
anchorOrigin={{ horizontal: 'right', vertical: 'top' }}
message="Snackbar should show left (RTL)"
open
/>
</Box>
</ThemeProvider>
</CacheProvider>
</StyleSheetManager>
);
}

0 comments on commit 96f5a72

Please sign in to comment.