Skip to content

Commit

Permalink
Update aria-expanded attribute in hide method
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit2sharma95 committed Mar 23, 2021
1 parent 232e392 commit 7c26426
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions js/src/dropdown.js
Expand Up @@ -224,6 +224,7 @@ class Dropdown extends BaseComponent {

this._menu.classList.toggle(CLASS_NAME_SHOW)
this._element.classList.toggle(CLASS_NAME_SHOW)
this._element.setAttribute('aria-expanded', 'false')
Manipulator.removeDataAttribute(this._menu, 'popper')
EventHandler.trigger(this._element, EVENT_HIDDEN, relatedTarget)
}
Expand Down Expand Up @@ -430,14 +431,13 @@ class Dropdown extends BaseComponent {
.forEach(elem => EventHandler.off(elem, 'mouseover', null, noop()))
}

toggles[i].setAttribute('aria-expanded', 'false')

if (context._popper) {
context._popper.destroy()
}

dropdownMenu.classList.remove(CLASS_NAME_SHOW)
toggles[i].classList.remove(CLASS_NAME_SHOW)
toggles[i].setAttribute('aria-expanded', 'false')
Manipulator.removeDataAttribute(dropdownMenu, 'popper')
EventHandler.trigger(toggles[i], EVENT_HIDDEN, relatedTarget)
}
Expand Down
3 changes: 2 additions & 1 deletion js/tests/unit/dropdown.spec.js
Expand Up @@ -743,7 +743,7 @@ describe('Dropdown', () => {
it('should hide a dropdown', done => {
fixtureEl.innerHTML = [
'<div class="dropdown">',
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>',
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="true">Dropdown</button>',
' <div class="dropdown-menu show">',
' <a class="dropdown-item" href="#">Secondary link</a>',
' </div>',
Expand All @@ -756,6 +756,7 @@ describe('Dropdown', () => {

btnDropdown.addEventListener('hidden.bs.dropdown', () => {
expect(dropdownMenu.classList.contains('show')).toEqual(false)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('false')
done()
})

Expand Down

0 comments on commit 7c26426

Please sign in to comment.