Skip to content

Commit

Permalink
Окончательно чинит управление фокусом
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaFokina committed May 20, 2024
1 parent f944b69 commit 65389dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/scripts/modules/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ class Header extends BaseComponent {
}

closeOnFocusout(event) {
if (!this.refs.rootElement.contains(event.relatedTarget)) {
if (event.relatedTarget && !this.refs.rootElement.contains(event.relatedTarget)) {
this.closeMenu()
}
}

closeOnClickOutside(event) {
if (!event.target.closest('.header__controls')) {
if (!this.refs.rootElement.contains(event.target)) {
this.closeMenu()
}
}
Expand All @@ -158,8 +158,8 @@ class Header extends BaseComponent {

document.removeEventListener('keyup', this.openOnKeyUp)
document.addEventListener('keyup', this.closeOnKeyUp)
rootElement.addEventListener('focusout', this.closeOnFocusout)
document.addEventListener('click', this.closeOnClickOutside)
document.addEventListener('focusout', this.closeOnFocusout)
}

closeMenu() {
Expand All @@ -169,14 +169,15 @@ class Header extends BaseComponent {
toggleButton.setAttribute('aria-expanded', 'false')

document.removeEventListener('keyup', this.closeOnKeyUp)
document.removeEventListener('click', this.closeOnClickOutside)
document.removeEventListener('focusout', this.closeOnFocusout)
document.removeEventListener('click', this.closeOnClickOutside)
document.addEventListener('keyup', this.openOnKeyUp)
this.focusOnLastElement()

this.emit('menu.close')
}

/* отслеживаем скролл, устанавливаем флаг для хедера */
stickyHeader(flag) {
this.refs.headerContent.classList.toggle('header__controls--shrink', flag)
document.documentElement.style.setProperty('--is-header-sticky', Number(flag))
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/modules/quick-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class QuickSearch extends BaseComponent {

closeSuggestionOnOutSideClick(event) {
const { rootElement } = this.refs
if (!rootElement.contains(event.target)) {
if (!rootElement.contains(event.target) && this.isSuggestionOpen) {
this.closeSuggestion()
}
}
Expand Down

0 comments on commit 65389dc

Please sign in to comment.