Skip to content

Commit 9a19d8c

Browse files
committed
fix: update _getOffset() to Popper 2
1 parent a38a154 commit 9a19d8c

File tree

2 files changed

+53
-29
lines changed

2 files changed

+53
-29
lines changed

js/src/dropdown.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* --------------------------------------------------------------------------
3-
* CoreUI (v3.2.0): dropdown.js
3+
* CoreUI (v3.2.1): dropdown.js
44
* Licensed under MIT (https://coreui.io/license)
55
*
66
* This component is a modified version of the Bootstrap's dropdown.js
@@ -30,7 +30,7 @@ import SelectorEngine from './dom/selector-engine'
3030
*/
3131

3232
const NAME = 'dropdown'
33-
const VERSION = '3.2.0'
33+
const VERSION = '3.2.1'
3434
const DATA_KEY = 'coreui.dropdown'
3535
const EVENT_KEY = `.${DATA_KEY}`
3636
const DATA_API_KEY = '.data-api'
@@ -255,7 +255,7 @@ class Dropdown {
255255
this._inNavbar = this._detectNavbar()
256256
this._inHeader = this._detectHeader()
257257
if (this._popper) {
258-
this._popper.scheduleUpdate()
258+
this._popper.update()
259259
}
260260
}
261261

@@ -320,20 +320,32 @@ class Dropdown {
320320
return Boolean(this._element.closest(`.${CLASS_NAME_HEADER}`))
321321
}
322322

323+
// _getOffset() {
324+
// const offset = {}
325+
326+
// if (typeof this._config.offset === 'function') {
327+
// offset.fn = data => {
328+
// data.offsets = {
329+
// ...data.offsets,
330+
// ...this._config.offset(data.offsets, this._element) || {}
331+
// }
332+
333+
// return data
334+
// }
335+
// } else {
336+
// offset.offset = this._config.offset
337+
// }
338+
339+
// return offset
340+
// }
341+
323342
_getOffset() {
324-
const offset = {}
343+
let offset = []
325344

326345
if (typeof this._config.offset === 'function') {
327-
offset.fn = data => {
328-
data.offsets = {
329-
...data.offsets,
330-
...this._config.offset(data.offsets, this._element) || {}
331-
}
332-
333-
return data
334-
}
346+
offset = ({ placement, reference, popper }) => this._config.offset({ placement, reference, popper })
335347
} else {
336-
offset.offset = this._config.offset
348+
offset = this._config.offset
337349
}
338350

339351
return offset
@@ -364,7 +376,8 @@ class Dropdown {
364376

365377
// Disable Popper.js if we have a static display
366378
if (this._config.display === 'static') {
367-
popperConfig.modifiers.applyStyle = {
379+
popperConfig.modifiers = {
380+
name: 'applyStyles',
368381
enabled: false
369382
}
370383
}

js/src/tooltip.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* --------------------------------------------------------------------------
3-
* CoreUI (v3.2.0): tooltip.js
3+
* CoreUI (v3.2.1): tooltip.js
44
* Licensed under MIT (https://coreui.io/license)
55
*
66
* This component is a modified version of the Bootstrap's tooltip.js
@@ -37,7 +37,7 @@ import SelectorEngine from './dom/selector-engine'
3737
*/
3838

3939
const NAME = 'tooltip'
40-
const VERSION = '3.2.0'
40+
const VERSION = '3.2.1'
4141
const DATA_KEY = 'coreui.tooltip'
4242
const EVENT_KEY = `.${DATA_KEY}`
4343
const CLASS_PREFIX = 'bs-tooltip'
@@ -53,7 +53,7 @@ const DefaultType = {
5353
html: 'boolean',
5454
selector: '(string|boolean)',
5555
placement: '(string|function)',
56-
offset: '(number|string|function)',
56+
offset: '(array|function)',
5757
container: '(string|element|boolean)',
5858
boundary: '(string|element)',
5959
sanitize: 'boolean',
@@ -81,7 +81,7 @@ const Default = {
8181
html: false,
8282
selector: false,
8383
placement: 'top',
84-
offset: 0,
84+
offset: [0, 0],
8585
container: false,
8686
boundary: 'scrollParent',
8787
sanitize: true,
@@ -497,20 +497,32 @@ class Tooltip {
497497
// this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
498498
// }
499499

500+
// _getOffset() {
501+
// const offset = {}
502+
503+
// if (typeof this.config.offset === 'function') {
504+
// offset.fn = data => {
505+
// data.offsets = {
506+
// ...data.offsets,
507+
// ...this.config.offset(data.offsets, this.element) || {}
508+
// }
509+
510+
// return data
511+
// }
512+
// } else {
513+
// offset.offset = this.config.offset
514+
// }
515+
516+
// return offset
517+
// }
518+
500519
_getOffset() {
501-
const offset = {}
520+
let offset = []
502521

503522
if (typeof this.config.offset === 'function') {
504-
offset.fn = data => {
505-
data.offsets = {
506-
...data.offsets,
507-
...this.config.offset(data.offsets, this.element) || {}
508-
}
509-
510-
return data
511-
}
523+
offset = ({ placement, reference, popper }) => this.config.offset(({ placement, reference, popper }))
512524
} else {
513-
offset.offset = this.config.offset
525+
offset = this.config.offset
514526
}
515527

516528
return offset
@@ -750,7 +762,6 @@ class Tooltip {
750762

751763
_cleanTipClass() {
752764
const tip = this.getTipElement()
753-
console.log(this.tip)
754765
const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
755766
if (tabClass !== null && tabClass.length > 0) {
756767
tabClass.map(token => token.trim())

0 commit comments

Comments
 (0)