Skip to content

Commit

Permalink
Удаляет метод с последним элементом
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaFokina committed May 30, 2024
1 parent 6b8b7df commit c67fa70
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/scripts/modules/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Header extends BaseComponent {
// stickyHeaderHeight: null,
lastScroll: 0,
getScrollThreshold: window.innerHeight,
lastFocusedElement: null,
}

const scrollThresholdConditions = [
Expand Down Expand Up @@ -58,7 +57,6 @@ class Header extends BaseComponent {
'closeOnKeyUp',
'closeOnClickOutside',
'closeOnFocusout',
'focusOnLastElement',
'openMenu',
'closeMenu',
'stickyHeader',
Expand All @@ -74,6 +72,8 @@ class Header extends BaseComponent {

const onResize = debounce(resizeCallback, 200)

this.state.lastFocusedElement = document.activeElement

window.addEventListener('resize', onResize)
window.addEventListener('orientationchange', onResize)
resizeCallback()
Expand Down Expand Up @@ -142,17 +142,9 @@ class Header extends BaseComponent {
}
}

focusOnLastElement() {
if (this.state.lastFocusedElement) {
this.state.lastFocusedElement.focus()
}
}

openMenu() {
const { rootElement, toggleButton } = this.refs

this.state.lastFocusedElement = document.activeElement

rootElement.classList.add(headerActiveClass)
toggleButton.setAttribute('aria-expanded', 'true')

Expand All @@ -172,7 +164,6 @@ class Header extends BaseComponent {
document.removeEventListener('focusout', this.closeOnFocusout)
document.removeEventListener('click', this.closeOnClickOutside)
document.addEventListener('keyup', this.openOnKeyUp)
this.focusOnLastElement()

this.emit('menu.close')
}
Expand Down

0 comments on commit c67fa70

Please sign in to comment.