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] Fix PaperProps.ref breaking positioning #26560

Merged
merged 3 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/material-ui/src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import useThemeProps from '../styles/useThemeProps';
import debounce from '../utils/debounce';
import ownerDocument from '../utils/ownerDocument';
import ownerWindow from '../utils/ownerWindow';
import useForkRef from '../utils/useForkRef';
import Grow from '../Grow';
import Modal from '../Modal';
import Paper from '../Paper';
Expand Down Expand Up @@ -120,6 +121,7 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
...other
} = props;
const paperRef = React.useRef();
const handlePaperRef = useForkRef(paperRef, PaperProps.ref);

const styleProps = {
...props,
Expand Down Expand Up @@ -369,8 +371,8 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
>
<PopoverPaper
elevation={elevation}
ref={paperRef}
{...PaperProps}
ref={handlePaperRef}
className={clsx(classes.paper, PaperProps.className)}
>
{children}
Expand Down
17 changes: 17 additions & 0 deletions packages/material-ui/src/Popover/Popover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ describe('<Popover />', () => {
});
});

describe('PaperProps.ref', () => {
it('should position popover correctly', () => {
const handleEntering = spy();
render(
<Popover
{...defaultProps}
open
PaperProps={{ 'data-testid': 'Popover', ref: () => null }}
TransitionProps={{ onEntering: handleEntering }}
>
<div />
</Popover>,
);
expect(handleEntering.args[0][0]).toHaveInlineStyle({ top: '16px', left: '16px' });
});
});

describe('transition lifecycle', () => {
describe('handleEntering(element)', () => {
it('should set the inline styles for the enter phase', () => {
Expand Down