Skip to content

Commit

Permalink
[Popper] Fix popperOptions prop (#15359)
Browse files Browse the repository at this point in the history
* [Popper] Fix overidden popperjs lifecycle options (#15262)
Fixes popperjs options for onUpdate and onCreate that were being spread over in Popper component

* fix formatting

* update test
  • Loading branch information
JaiPe authored and oliviertassinari committed Apr 17, 2019
1 parent e470b1b commit 138cc30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/material-ui/src/Popper/Popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PopperJS from 'popper.js';
import { chainPropTypes } from '@material-ui/utils';
import Portal from '../Portal';
import { setRef, withForwardedRef } from '../utils';
import { createChainedFunction } from '../utils/helpers';

function flipPlacement(placement) {
const direction = (typeof window !== 'undefined' && document.body.getAttribute('dir')) || 'ltr';
Expand Down Expand Up @@ -96,8 +97,8 @@ class Popper extends React.Component {
},
// We could have been using a custom modifier like react-popper is doing.
// But it seems this is the best public API for this use case.
onCreate: this.handlePopperUpdate,
onUpdate: this.handlePopperUpdate,
onCreate: createChainedFunction(this.handlePopperUpdate, popperOptions.onCreate),
onUpdate: createChainedFunction(this.handlePopperUpdate, popperOptions.onUpdate),
});
};

Expand Down
14 changes: 14 additions & 0 deletions packages/material-ui/src/Popper/Popper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ describe('<Popper />', () => {
});
});

describe('prop: popperOptions', () => {
it('should pass all popperOptions to popperjs', done => {
const popperOptions = {
onCreate: data => {
data.instance.update({ placement: 'left' });
},
onUpdate: () => {
done();
},
};
mount(<Popper {...defaultProps} popperOptions={popperOptions} placement="top" open />);
});
});

describe('prop: keepMounted', () => {
describe('by default', () => {
// Test case for https://github.com/mui-org/material-ui/issues/15180
Expand Down

0 comments on commit 138cc30

Please sign in to comment.