Skip to content

Commit a4fe099

Browse files
authored
Fix some JS todos and warnings (#41998)
* Fix some JS todos and warnings * Undo some
1 parent 44ef0da commit a4fe099

7 files changed

Lines changed: 28 additions & 65 deletions

File tree

js/src/carousel.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const Default = {
7676
}
7777

7878
const DefaultType = {
79-
interval: '(number|boolean)', // TODO:v6 remove boolean support
79+
interval: 'number',
8080
keyboard: 'boolean',
8181
pause: '(string|boolean)',
8282
ride: '(boolean|string)',
@@ -125,10 +125,9 @@ class Carousel extends BaseComponent {
125125
}
126126

127127
nextWhenVisible() {
128-
// FIXME TODO use `document.visibilityState`
129128
// Don't call next when the page isn't visible
130129
// or the carousel or its parent isn't visible
131-
if (!document.hidden && isVisible(this._element)) {
130+
if (document.visibilityState === 'visible' && isVisible(this._element)) {
132131
this.next()
133132
}
134133
}
@@ -328,7 +327,6 @@ class Carousel extends BaseComponent {
328327

329328
if (!activeElement || !nextElement) {
330329
// Some weirdness is happening, so we bail
331-
// TODO: change tests that use empty divs to avoid this check
332330
return
333331
}
334332

js/src/dom/event-handler.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ function findHandler(events, callable, delegationSelector = null) {
126126

127127
function normalizeParameters(originalTypeEvent, handler, delegationFunction) {
128128
const isDelegated = typeof handler === 'string'
129-
// TODO: tooltip passes `false` instead of selector, so we need to check
130129
const callable = isDelegated ? delegationFunction : (handler || delegationFunction)
131130
let typeEvent = getTypeEvent(originalTypeEvent)
132131

js/src/dom/selector-engine.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const SelectorEngine = {
7070

7171
return []
7272
},
73+
7374
// TODO: this is now unused; remove later along with prev()
7475
next(element, selector) {
7576
let next = element.nextElementSibling

js/src/scrollspy.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ const SELECTOR_DROPDOWN = '.dropdown'
3939
const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle'
4040

4141
const Default = {
42-
offset: null, // TODO: v6 @deprecated, keep it for backwards compatibility reasons
4342
rootMargin: '0px 0px -25%',
4443
smoothScroll: false,
4544
target: null,
4645
threshold: [0.1, 0.5, 1]
4746
}
4847

4948
const DefaultType = {
50-
offset: '(number|null)', // TODO v6 @deprecated, keep it for backwards compatibility reasons
5149
rootMargin: 'string',
5250
smoothScroll: 'boolean',
5351
target: 'element',
@@ -111,12 +109,8 @@ class ScrollSpy extends BaseComponent {
111109

112110
// Private
113111
_configAfterMerge(config) {
114-
// TODO: on v6 target should be given explicitly & remove the {target: 'ss-target'} case
115112
config.target = getElement(config.target) || document.body
116113

117-
// TODO: v6 Only for backwards compatibility reasons. Use rootMargin only
118-
config.rootMargin = config.offset ? `${config.offset}px 0px -30%` : config.rootMargin
119-
120114
if (typeof config.threshold === 'string') {
121115
config.threshold = config.threshold.split(',').map(value => Number.parseFloat(value))
122116
}

js/src/tab.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Tab extends BaseComponent {
6262
if (!this._parent) {
6363
return
6464
// TODO: should throw exception in v6
65-
// throw new TypeError(`${element.outerHTML} has not a valid parent ${SELECTOR_INNER_ELEM}`)
65+
// throw new TypeError(`${element.outerHTML} has not a valid parent ${SELECTOR_TAB_PANEL}`)
6666
}
6767

6868
// Set up initial aria attributes

js/src/tooltip.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,7 @@ class Tooltip extends BaseComponent {
320320
_createTipElement(content) {
321321
const tip = this._getTemplateFactory(content).toHtml()
322322

323-
// TODO: remove this check in v6
324-
if (!tip) {
325-
return null
326-
}
327-
328323
tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW)
329-
// TODO: v6 the following can be achieved with CSS only
330324
tip.classList.add(`bs-${this.constructor.NAME}-auto`)
331325

332326
const tipId = getUID(this.constructor.NAME).toString()

js/tests/unit/dropdown.spec.js

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -59,60 +59,37 @@ describe('Dropdown', () => {
5959
expect(dropdownByElement._element).toEqual(btnDropdown)
6060
})
6161

62-
it('should work on invalid markup', () => {
63-
return new Promise(resolve => {
64-
// TODO: REMOVE in v6
65-
fixtureEl.innerHTML = [
66-
'<div class="dropdown">',
67-
' <div class="dropdown-menu">',
68-
' <a class="dropdown-item" href="#">Link</a>',
69-
' </div>',
70-
'</div>'
71-
].join('')
72-
73-
const dropdownElem = fixtureEl.querySelector('.dropdown-menu')
74-
const dropdown = new Dropdown(dropdownElem)
75-
76-
dropdownElem.addEventListener('shown.bs.dropdown', () => {
77-
resolve()
78-
})
62+
it('should create offset modifier correctly when offset option is a function', async () => {
63+
fixtureEl.innerHTML = [
64+
'<div class="dropdown">',
65+
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>',
66+
' <div class="dropdown-menu">',
67+
' <a class="dropdown-item" href="#">Secondary link</a>',
68+
' </div>',
69+
'</div>'
70+
].join('')
7971

80-
expect().nothing()
81-
dropdown.show()
72+
const getOffset = jasmine.createSpy('getOffset').and.returnValue([10, 20])
73+
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
74+
const dropdown = new Dropdown(btnDropdown, {
75+
offset: getOffset
8276
})
83-
})
84-
85-
it('should create offset modifier correctly when offset option is a function', () => {
86-
return new Promise(resolve => {
87-
fixtureEl.innerHTML = [
88-
'<div class="dropdown">',
89-
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>',
90-
' <div class="dropdown-menu">',
91-
' <a class="dropdown-item" href="#">Secondary link</a>',
92-
' </div>',
93-
'</div>'
94-
].join('')
9577

96-
const getOffset = jasmine.createSpy('getOffset').and.returnValue([10, 20])
97-
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
98-
const dropdown = new Dropdown(btnDropdown, {
99-
offset: getOffset
100-
})
78+
const offset = dropdown._getOffset()
79+
expect(typeof offset).toEqual('function')
10180

102-
btnDropdown.addEventListener('shown.bs.dropdown', () => {
103-
// Floating UI calls offset function asynchronously
104-
setTimeout(() => {
105-
expect(getOffset).toHaveBeenCalled()
106-
resolve()
107-
}, 20)
108-
})
109-
110-
const offset = dropdown._getOffset()
81+
const shownPromise = new Promise(resolve => {
82+
btnDropdown.addEventListener('shown.bs.dropdown', resolve)
83+
})
11184

112-
expect(typeof offset).toEqual('function')
85+
dropdown.show()
86+
await shownPromise
11387

114-
dropdown.show()
88+
// Floating UI calls offset function asynchronously
89+
await new Promise(resolve => {
90+
setTimeout(resolve, 20)
11591
})
92+
expect(getOffset).toHaveBeenCalled()
11693
})
11794

11895
it('should create offset modifier correctly when offset option is a string into data attribute', () => {

0 commit comments

Comments
 (0)