@@ -32,6 +32,18 @@ export default class EmberPopperBase extends Component {
32
32
*/
33
33
@property onFoundTarget = null
34
34
35
+ /**
36
+ * onCreate callback merged (if present) into the Popper instance's options hash.
37
+ * https://popper.js.org/popper-documentation.html#Popper.Defaults.onCreate
38
+ */
39
+ @property onCreate = null
40
+
41
+ /**
42
+ * onUpdate callback merged (if present) into the Popper instance's options hash.
43
+ * https://popper.js.org/popper-documentation.html#Popper.Defaults.onUpdate
44
+ */
45
+ @property onUpdate = null
46
+
35
47
/**
36
48
* Placement of the popper. One of ['top', 'right', 'bottom', 'left'].
37
49
*/
@@ -100,6 +112,16 @@ export default class EmberPopperBase extends Component {
100
112
*/
101
113
@property _updateRAF = null
102
114
115
+ /**
116
+ * Tracks current/previous value of `onCreate` callback
117
+ */
118
+ @property _onCreate = null
119
+
120
+ /**
121
+ * Tracks current/previous value of `onUpdate` callback
122
+ */
123
+ @property _onUpdate = null
124
+
103
125
// ================== LIFECYCLE HOOKS ==================
104
126
105
127
didUpdateAttrs ( ) {
@@ -153,6 +175,7 @@ export default class EmberPopperBase extends Component {
153
175
const eventsEnabled = this . get ( 'eventsEnabled' ) ;
154
176
const modifiers = this . get ( 'modifiers' ) ;
155
177
const placement = this . get ( 'placement' ) ;
178
+ const { onCreate, onUpdate } = this ;
156
179
157
180
const isPopperTargetDifferent = popperTarget !== this . _popperTarget ;
158
181
@@ -161,7 +184,9 @@ export default class EmberPopperBase extends Component {
161
184
|| isPopperTargetDifferent
162
185
|| eventsEnabled !== this . _eventsEnabled
163
186
|| modifiers !== this . _modifiers
164
- || placement !== this . _placement ;
187
+ || placement !== this . _placement
188
+ || onCreate !== this . _onCreate
189
+ || onUpdate !== this . _onUpdate ;
165
190
166
191
if ( didChange === true ) {
167
192
if ( this . _popper !== null ) {
@@ -176,8 +201,26 @@ export default class EmberPopperBase extends Component {
176
201
this . _eventsEnabled = eventsEnabled ;
177
202
this . _modifiers = modifiers ;
178
203
this . _placement = placement ;
204
+ this . _onCreate = onCreate ;
205
+ this . _onUpdate = onUpdate ;
206
+
207
+ const options = {
208
+ eventsEnabled,
209
+ modifiers,
210
+ placement
211
+ } ;
212
+
213
+ if ( onCreate ) {
214
+ assert ( 'onCreate of ember-popper must be a function' , typeof onCreate === 'function' ) ;
215
+ options . onCreate = onCreate ;
216
+ }
217
+
218
+ if ( onUpdate ) {
219
+ assert ( 'onUpdate of ember-popper must be a function' , typeof onUpdate === 'function' ) ;
220
+ options . onUpdate = onUpdate ;
221
+ }
179
222
180
- this . _popper = new Popper ( popperTarget , popperElement , { eventsEnabled , modifiers , placement } ) ;
223
+ this . _popper = new Popper ( popperTarget , popperElement , options ) ;
181
224
182
225
// Execute the onFoundTarget hook last to ensure the Popper is initialized on the target
183
226
if ( isPopperTargetDifferent && this . get ( 'onFoundTarget' ) ) {
0 commit comments