Skip to content

Commit

Permalink
Remove onFirstUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed Jul 12, 2020
1 parent a152867 commit 1962c9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
6 changes: 1 addition & 5 deletions packages/material-ui/src/Popper/Popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createPopper } from '@popperjs/core';
import { chainPropTypes, refType, HTMLElementType } from '@material-ui/utils';
import { useTheme } from '@material-ui/styles';
import Portal from '../Portal';
import createChainedFunction from '../utils/createChainedFunction';
import setRef from '../utils/setRef';
import useForkRef from '../utils/useForkRef';

Expand Down Expand Up @@ -139,7 +138,7 @@ const Popper = React.forwardRef(function Popper(props, ref) {
enabled: true,
phase: 'afterWrite',
fn({ state }) {
createChainedFunction(handlePopperUpdate, popperOptions.onUpdate)(state);
handlePopperUpdate(state);
},
},
];
Expand All @@ -155,9 +154,6 @@ const Popper = React.forwardRef(function Popper(props, ref) {
placement: rtlPlacement,
...popperOptions,
modifiers: popperModifiers,
// 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.
onFirstUpdate: createChainedFunction(handlePopperUpdate, popperOptions.onFirstUpdate),
});

handlePopperRefRef.current(popper);
Expand Down
34 changes: 16 additions & 18 deletions packages/material-ui/src/Popper/Popper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,7 @@ describe('<Popper />', () => {
);
expect(renderSpy.args).to.deep.equal([['bottom'], ['bottom']]);
await popperRef.current.setOptions({ placement: 'top' });
expect(renderSpy.args).to.deep.equal([
['bottom'],
['bottom'],
['top'],
['top'],
['top'],
['top'],
]);
expect(renderSpy.args).to.deep.equal([['bottom'], ['bottom'], ['top'], ['top']]);
});
});

Expand All @@ -140,16 +133,21 @@ describe('<Popper />', () => {
});

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

expect(popperRef.current.state.placement).to.equal('bottom');
});
});

Expand Down

0 comments on commit 1962c9b

Please sign in to comment.