@@ -46,9 +46,8 @@ class Popper extends Component {
4646 this . _destroyPopper ( )
4747 this . _createPopper ( )
4848 }
49-
5049 if ( lastProps . children !== this . props . children ) {
51- this . _popper . scheduleUpdate ( )
50+ this . _scheduleUpdate ( )
5251 }
5352 }
5453
@@ -64,26 +63,14 @@ class Popper extends Component {
6463 return this . context . popperManager . getTargetNode ( )
6564 }
6665
67- _getOffsets = data => {
68- return Object . keys ( data . offsets ) . map ( key => data . offsets [ key ] )
69- }
70-
71- _isDataDirty = data => {
72- if ( this . state . data ) {
73- return (
74- JSON . stringify ( this . _getOffsets ( this . state . data ) ) !==
75- JSON . stringify ( this . _getOffsets ( data ) )
76- )
77- } else {
78- return true
79- }
80- }
81-
8266 _updateStateModifier = {
8367 enabled : true ,
8468 order : 900 ,
8569 fn : data => {
86- if ( this . _isDataDirty ( data ) ) {
70+ if (
71+ data . placement !== this . state . placement ||
72+ data . hide !== this . state . hide
73+ ) {
8774 this . setState ( { data } )
8875 }
8976 return data
@@ -94,25 +81,18 @@ class Popper extends Component {
9481 const { placement, eventsEnabled } = this . props
9582 const modifiers = {
9683 ...this . props . modifiers ,
97- applyStyle : { enabled : false } ,
9884 updateState : this . _updateStateModifier ,
9985 }
100-
10186 if ( this . _arrowNode ) {
10287 modifiers . arrow = {
10388 element : this . _arrowNode ,
10489 }
10590 }
106-
10791 this . _popper = new PopperJS ( this . _getTargetNode ( ) , this . _node , {
10892 placement,
10993 eventsEnabled,
11094 modifiers,
11195 } )
112-
113- // schedule an update to make sure everything gets positioned correctly
114- // after being instantiated
115- this . _popper . scheduleUpdate ( )
11696 }
11797
11898 _destroyPopper ( ) {
@@ -121,27 +101,6 @@ class Popper extends Component {
121101 }
122102 }
123103
124- _getPopperStyle = ( ) => {
125- const { data } = this . state
126-
127- // If Popper isn't instantiated, hide the popperElement
128- // to avoid flash of unstyled content
129- if ( ! data ) {
130- return {
131- position : 'absolute' ,
132- pointerEvents : 'none' ,
133- opacity : 0 ,
134- }
135- }
136-
137- const { top, left, position } = data . offsets . popper
138-
139- return {
140- position,
141- ...data . styles ,
142- }
143- }
144-
145104 _getPopperPlacement = ( ) => {
146105 return this . state . data ? this . state . data . placement : undefined
147106 }
@@ -159,18 +118,22 @@ class Popper extends Component {
159118 }
160119 }
161120
162- _getPopperRef = ( node ) => {
121+ _getPopperRef = node => {
163122 this . _node = node
164123 if ( node ) {
165- this . _createPopper ( ) ;
124+ this . _createPopper ( )
166125 } else {
167- this . _destroyPopper ( ) ;
126+ this . _destroyPopper ( )
168127 }
169128 if ( this . props . innerRef ) {
170129 this . props . innerRef ( node )
171130 }
172131 }
173132
133+ _scheduleUpdate = ( ) => {
134+ this . _popper && this . _popper . scheduleUpdate ( )
135+ }
136+
174137 render ( ) {
175138 const {
176139 component,
@@ -181,36 +144,24 @@ class Popper extends Component {
181144 children,
182145 ...restProps
183146 } = this . props
184- const popperStyle = this . _getPopperStyle ( )
185147 const popperPlacement = this . _getPopperPlacement ( )
186148 const popperHide = this . _getPopperHide ( )
187149
188150 if ( typeof children === 'function' ) {
189151 const popperProps = {
190152 ref : this . _getPopperRef ,
191- style : popperStyle ,
192153 [ 'data-placement' ] : popperPlacement ,
193154 [ 'data-x-out-of-boundaries' ] : popperHide ,
194155 }
195-
196156 return children ( {
197157 popperProps,
198158 restProps,
199- scheduleUpdate : ( ) => {
200- // _createPopper will scheduleUpdate,
201- // so calling this before this._popper exists
202- // can be a noop.
203- this . _popper && this . _popper . scheduleUpdate ( ) ;
204- } ,
159+ scheduleUpdate : this . _scheduleUpdate ,
205160 } )
206161 }
207162
208163 const componentProps = {
209164 ...restProps ,
210- style : {
211- ...restProps . style ,
212- ...popperStyle ,
213- } ,
214165 'data-placement' : popperPlacement ,
215166 'data-x-out-of-boundaries' : popperHide ,
216167 }
0 commit comments