mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-22 06:39:52 +00:00
Skip hidden dropdowns while focusing (#29523)
This commit is contained in:
parent
104385c508
commit
c1ee395f80
@ -9,6 +9,7 @@ import {
|
|||||||
getjQuery,
|
getjQuery,
|
||||||
getElementFromSelector,
|
getElementFromSelector,
|
||||||
isElement,
|
isElement,
|
||||||
|
isVisible,
|
||||||
makeArray,
|
makeArray,
|
||||||
noop,
|
noop,
|
||||||
typeCheckConfig
|
typeCheckConfig
|
||||||
@ -478,6 +479,7 @@ class Dropdown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const items = makeArray(SelectorEngine.find(Selector.VISIBLE_ITEMS, parent))
|
const items = makeArray(SelectorEngine.find(Selector.VISIBLE_ITEMS, parent))
|
||||||
|
.filter(isVisible)
|
||||||
|
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
return
|
return
|
||||||
|
@ -138,9 +138,12 @@ const isVisible = element => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element.style && element.parentNode && element.parentNode.style) {
|
if (element.style && element.parentNode && element.parentNode.style) {
|
||||||
return element.style.display !== 'none' &&
|
const elementStyle = getComputedStyle(element)
|
||||||
element.parentNode.style.display !== 'none' &&
|
const parentNodeStyle = getComputedStyle(element.parentNode)
|
||||||
element.style.visibility !== 'hidden'
|
|
||||||
|
return elementStyle.display !== 'none' &&
|
||||||
|
parentNodeStyle.display !== 'none' &&
|
||||||
|
elementStyle.visibility !== 'hidden'
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -1292,6 +1292,43 @@ describe('Dropdown', () => {
|
|||||||
triggerDropdown.click()
|
triggerDropdown.click()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should skip hidden element when using keyboard navigation', done => {
|
||||||
|
fixtureEl.innerHTML = [
|
||||||
|
'<style>',
|
||||||
|
' .d-none {',
|
||||||
|
' display: none;',
|
||||||
|
' }',
|
||||||
|
'</style>',
|
||||||
|
'<div class="dropdown">',
|
||||||
|
' <button href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>',
|
||||||
|
' <div class="dropdown-menu">',
|
||||||
|
' <button class="dropdown-item d-none" type="button">Hidden button by class</button>',
|
||||||
|
' <a class="dropdown-item" href="#sub1" style="display: none">Hidden link</a>',
|
||||||
|
' <a class="dropdown-item" href="#sub1" style="visibility: hidden">Hidden link</a>',
|
||||||
|
' <a id="item1" class="dropdown-item" href="#">Another link</a>',
|
||||||
|
' </div>',
|
||||||
|
'</div>'
|
||||||
|
].join('')
|
||||||
|
|
||||||
|
const triggerDropdown = fixtureEl.querySelector('[data-toggle="dropdown"]')
|
||||||
|
const dropdown = fixtureEl.querySelector('.dropdown')
|
||||||
|
|
||||||
|
dropdown.addEventListener('shown.bs.dropdown', () => {
|
||||||
|
const keyDown = createEvent('keydown')
|
||||||
|
keyDown.which = 40
|
||||||
|
|
||||||
|
triggerDropdown.dispatchEvent(keyDown)
|
||||||
|
|
||||||
|
expect(document.activeElement.classList.contains('d-none')).toEqual(false, '.d-none not focused')
|
||||||
|
expect(document.activeElement.style.display === 'none').toEqual(false, '"display: none" not focused')
|
||||||
|
expect(document.activeElement.style.visibility === 'hidden').toEqual(false, '"visibility: hidden" not focused')
|
||||||
|
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
triggerDropdown.click()
|
||||||
|
})
|
||||||
|
|
||||||
it('should focus next/previous element when using keyboard navigation', done => {
|
it('should focus next/previous element when using keyboard navigation', done => {
|
||||||
fixtureEl.innerHTML = [
|
fixtureEl.innerHTML = [
|
||||||
'<div class="dropdown">',
|
'<div class="dropdown">',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user