}
const DefaultType = {
- interval: '(number|boolean)', // TODO:v6 remove boolean support
+ interval: 'number',
keyboard: 'boolean',
pause: '(string|boolean)',
ride: '(boolean|string)',
}
nextWhenVisible() {
- // FIXME TODO use `document.visibilityState`
// Don't call next when the page isn't visible
// or the carousel or its parent isn't visible
- if (!document.hidden && isVisible(this._element)) {
+ if (document.visibilityState === 'visible' && isVisible(this._element)) {
this.next()
}
}
if (!activeElement || !nextElement) {
// Some weirdness is happening, so we bail
- // TODO: change tests that use empty divs to avoid this check
return
}
const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle'
const Default = {
- offset: null, // TODO: v6 @deprecated, keep it for backwards compatibility reasons
rootMargin: '0px 0px -25%',
smoothScroll: false,
target: null,
}
const DefaultType = {
- offset: '(number|null)', // TODO v6 @deprecated, keep it for backwards compatibility reasons
rootMargin: 'string',
smoothScroll: 'boolean',
target: 'element',
// Private
_configAfterMerge(config) {
- // TODO: on v6 target should be given explicitly & remove the {target: 'ss-target'} case
config.target = getElement(config.target) || document.body
- // TODO: v6 Only for backwards compatibility reasons. Use rootMargin only
- config.rootMargin = config.offset ? `${config.offset}px 0px -30%` : config.rootMargin
-
if (typeof config.threshold === 'string') {
config.threshold = config.threshold.split(',').map(value => Number.parseFloat(value))
}
expect(dropdownByElement._element).toEqual(btnDropdown)
})
- it('should work on invalid markup', () => {
- return new Promise(resolve => {
- // TODO: REMOVE in v6
- fixtureEl.innerHTML = [
- '<div class="dropdown">',
- ' <div class="dropdown-menu">',
- ' <a class="dropdown-item" href="#">Link</a>',
- ' </div>',
- '</div>'
- ].join('')
-
- const dropdownElem = fixtureEl.querySelector('.dropdown-menu')
- const dropdown = new Dropdown(dropdownElem)
-
- dropdownElem.addEventListener('shown.bs.dropdown', () => {
- resolve()
- })
+ it('should create offset modifier correctly when offset option is a function', async () => {
+ fixtureEl.innerHTML = [
+ '<div class="dropdown">',
+ ' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>',
+ ' <div class="dropdown-menu">',
+ ' <a class="dropdown-item" href="#">Secondary link</a>',
+ ' </div>',
+ '</div>'
+ ].join('')
- expect().nothing()
- dropdown.show()
+ const getOffset = jasmine.createSpy('getOffset').and.returnValue([10, 20])
+ const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
+ const dropdown = new Dropdown(btnDropdown, {
+ offset: getOffset
})
- })
-
- it('should create offset modifier correctly when offset option is a function', () => {
- return new Promise(resolve => {
- fixtureEl.innerHTML = [
- '<div class="dropdown">',
- ' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>',
- ' <div class="dropdown-menu">',
- ' <a class="dropdown-item" href="#">Secondary link</a>',
- ' </div>',
- '</div>'
- ].join('')
- const getOffset = jasmine.createSpy('getOffset').and.returnValue([10, 20])
- const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
- const dropdown = new Dropdown(btnDropdown, {
- offset: getOffset
- })
+ const offset = dropdown._getOffset()
+ expect(typeof offset).toEqual('function')
- btnDropdown.addEventListener('shown.bs.dropdown', () => {
- // Floating UI calls offset function asynchronously
- setTimeout(() => {
- expect(getOffset).toHaveBeenCalled()
- resolve()
- }, 20)
- })
-
- const offset = dropdown._getOffset()
+ const shownPromise = new Promise(resolve => {
+ btnDropdown.addEventListener('shown.bs.dropdown', resolve)
+ })
- expect(typeof offset).toEqual('function')
+ dropdown.show()
+ await shownPromise
- dropdown.show()
+ // Floating UI calls offset function asynchronously
+ await new Promise(resolve => {
+ setTimeout(resolve, 20)
})
+ expect(getOffset).toHaveBeenCalled()
})
it('should create offset modifier correctly when offset option is a string into data attribute', () => {