Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Popover] Add ownerState on the paper slot #34445

Merged
merged 3 commits into from Sep 28, 2022

Conversation

kabernardes
Copy link
Contributor

This PR fixes #34404

As explained in issue #34404, ownerState was missing in Popover.

@mui-bot
Copy link

mui-bot commented Sep 23, 2022

Details of bundle changes

Generated by 🚫 dangerJS against 720d6ca

@kabernardes kabernardes marked this pull request as ready for review September 23, 2022 15:58
@kabernardes
Copy link
Contributor Author

I just have some trouble with the label at the CI, if that is something that I need to do to correct this, just let me know.

@ZeeshanTamboli ZeeshanTamboli changed the title [component: Popover] Add ownerState to Popover [Popover] Add ownerState to Popover Sep 24, 2022
@ZeeshanTamboli ZeeshanTamboli added bug 🐛 Something doesn't work component: Popover The React component. package: material-ui Specific to @mui/material labels Sep 24, 2022
@ZeeshanTamboli ZeeshanTamboli changed the title [Popover] Add ownerState to Popover [Popover] Add ownerState Sep 24, 2022
@mnajdova mnajdova changed the title [Popover] Add ownerState [Popover] Add ownerState on the paper slot Sep 26, 2022
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good. Let's add a test for it (in Popover.test.js):

index e9e0d21116..465503305e 100644
--- a/packages/mui-material/src/Popover/Popover.test.js
+++ b/packages/mui-material/src/Popover/Popover.test.js
@@ -7,6 +7,7 @@ import Grow from '@mui/material/Grow';
 import Modal from '@mui/material/Modal';
 import Paper from '@mui/material/Paper';
 import Popover, { popoverClasses as classes } from '@mui/material/Popover';
+import { ThemeProvider, createTheme } from '@mui/material/styles';
 import { getOffsetLeft, getOffsetTop } from './Popover';
 import useForkRef from '../utils/useForkRef';

@@ -877,4 +878,26 @@ describe('<Popover />', () => {
       expect(screen.getByTestId('transition')).not.to.have.attribute('data-timeout');
     });
   });
+
+  it("should not throw if ownerState is used in slot's styleOverrides", () => {
+    expect(() =>
+      render(
+        <ThemeProvider
+          theme={createTheme({
+            components: {
+              MuiPopover: {
+                styleOverrides: {
+                  paper: ({ ownerState }) => ({
+                    marginTop: ownerState.transformOrigin?.vertical === 'top' ? '4px' : 0,
+                  }),
+                },
+              },
+            },
+          })}
+        >
+          <Popover anchorEl={document.createElement('div')} open><div /></Popover>
+        </ThemeProvider>,
+      ),
+    ).not.to.throw();
+  });
 });

The test basically ensures that accessing ownerState in the style overrides for the paper in the Popover, won't throw.

@kabernardes
Copy link
Contributor Author

The fix looks good. Let's add a test for it (in Popover.test.js):

index e9e0d21116..465503305e 100644
--- a/packages/mui-material/src/Popover/Popover.test.js
+++ b/packages/mui-material/src/Popover/Popover.test.js
@@ -7,6 +7,7 @@ import Grow from '@mui/material/Grow';
 import Modal from '@mui/material/Modal';
 import Paper from '@mui/material/Paper';
 import Popover, { popoverClasses as classes } from '@mui/material/Popover';
+import { ThemeProvider, createTheme } from '@mui/material/styles';
 import { getOffsetLeft, getOffsetTop } from './Popover';
 import useForkRef from '../utils/useForkRef';

@@ -877,4 +878,26 @@ describe('<Popover />', () => {
       expect(screen.getByTestId('transition')).not.to.have.attribute('data-timeout');
     });
   });
+
+  it("should not throw if ownerState is used in slot's styleOverrides", () => {
+    expect(() =>
+      render(
+        <ThemeProvider
+          theme={createTheme({
+            components: {
+              MuiPopover: {
+                styleOverrides: {
+                  paper: ({ ownerState }) => ({
+                    marginTop: ownerState.transformOrigin?.vertical === 'top' ? '4px' : 0,
+                  }),
+                },
+              },
+            },
+          })}
+        >
+          <Popover anchorEl={document.createElement('div')} open><div /></Popover>
+        </ThemeProvider>,
+      ),
+    ).not.to.throw();
+  });
 });

The test basically ensures that accessing ownerState in the style overrides for the paper in the Popover, won't throw.

Done, if you need anything else, please, let me know.

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the contribution!

@mnajdova mnajdova merged commit b2f2f05 into mui:master Sep 28, 2022
alexfauquette pushed a commit to alexfauquette/material-ui that referenced this pull request Oct 14, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: Popover The React component. package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Menu] ownerState is undefined when the Menu is opened
4 participants