mirror of https://github.com/twbs/bootstrap.git
Merge 0fabd40453
into 4c98145482
This commit is contained in:
commit
fa530f0232
|
@ -57,6 +57,10 @@ const SelectorEngine = {
|
||||||
return parents
|
return parents
|
||||||
},
|
},
|
||||||
|
|
||||||
|
closest(element, selector) {
|
||||||
|
return Element.prototype.closest.call(element, selector)
|
||||||
|
},
|
||||||
|
|
||||||
prev(element, selector) {
|
prev(element, selector) {
|
||||||
let previous = element.previousElementSibling
|
let previous = element.previousElementSibling
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,8 @@ class Dropdown extends BaseComponent {
|
||||||
super(element, config)
|
super(element, config)
|
||||||
|
|
||||||
this._popper = null
|
this._popper = null
|
||||||
this._parent = this._element.parentNode // dropdown wrapper
|
const wrapperSelector = `:has(${SELECTOR_MENU})`
|
||||||
|
this._parent = SelectorEngine.closest(element, wrapperSelector) // dropdown wrapper
|
||||||
// TODO: v6 revert #37011 & change markup https://getbootstrap.com/docs/5.3/forms/input-group/
|
// TODO: v6 revert #37011 & change markup https://getbootstrap.com/docs/5.3/forms/input-group/
|
||||||
this._menu = SelectorEngine.next(this._element, SELECTOR_MENU)[0] ||
|
this._menu = SelectorEngine.next(this._element, SELECTOR_MENU)[0] ||
|
||||||
SelectorEngine.prev(this._element, SELECTOR_MENU)[0] ||
|
SelectorEngine.prev(this._element, SELECTOR_MENU)[0] ||
|
||||||
|
|
|
@ -81,6 +81,28 @@ describe('SelectorEngine', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('closest', () => {
|
||||||
|
it('should return one element when element with selector is the direct parent', () => {
|
||||||
|
const testId = 'test'
|
||||||
|
fixtureEl.innerHTML = `<div id="${testId}"><div id="element"></div></div>`
|
||||||
|
|
||||||
|
const element = fixtureEl.querySelector('#element')
|
||||||
|
const parent = fixtureEl.querySelector(`#${testId}`)
|
||||||
|
|
||||||
|
expect(SelectorEngine.closest(element, `#${testId}`)).toEqual(parent)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return one element when element with selector is an ancestor', () => {
|
||||||
|
const testId = 'test'
|
||||||
|
fixtureEl.innerHTML = `<div id="${testId}"><div><div id="element"></div></div></div>`
|
||||||
|
|
||||||
|
const element = fixtureEl.querySelector('#element')
|
||||||
|
const ancestor = fixtureEl.querySelector(`#${testId}`)
|
||||||
|
|
||||||
|
expect(SelectorEngine.closest(element, `#${testId}`)).toEqual(ancestor)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('prev', () => {
|
describe('prev', () => {
|
||||||
it('should return previous element', () => {
|
it('should return previous element', () => {
|
||||||
fixtureEl.innerHTML = '<div class="test"></div><button class="btn"></button>'
|
fixtureEl.innerHTML = '<div class="test"></div><button class="btn"></button>'
|
||||||
|
|
Loading…
Reference in New Issue