-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
50 additions
and
85 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import useEvent from './event/useEvent'; | ||
|
||
const useTopMenu = (selector) => { | ||
const { on, off } = useEvent(); | ||
const menuElement = document.querySelector(selector); | ||
const DOM_SELECTORS = { | ||
SUB_ELEMENTS: '.main-menu__item--top', | ||
SUB_MENU: '.main-menu__sub', | ||
}; | ||
const ITEM_ACTIVE = 'main-menu__item--active'; | ||
|
||
|
||
const toggleSubMenu = (e) => { | ||
const { currentTarget } = e; | ||
const { SUB_MENU } = DOM_SELECTORS; | ||
const expanded = currentTarget.getAttribute('aria-expanded'); | ||
const isExpanded = expanded && expanded.toLowerCase() === 'true'; | ||
const subMenu = currentTarget.querySelector(SUB_MENU); | ||
|
||
currentTarget.classList.toggle(ITEM_ACTIVE); | ||
|
||
if (subMenu) { | ||
currentTarget.setAttribute('aria-expanded', !isExpanded); | ||
|
||
subMenu.setAttribute('aria-hidden', isExpanded); | ||
subMenu.setAttribute('aria-expanded', !isExpanded); | ||
|
||
} | ||
} | ||
|
||
const init = () => { | ||
debugger | ||
Check failure on line 32 in _dev/js/theme/components/useTopMenu.js GitHub Actions / Code quality - ESLint
|
||
const { SUB_ELEMENTS } = DOM_SELECTORS; | ||
|
||
off(menuElement, 'mouseenter', SUB_ELEMENTS, toggleSubMenu); | ||
off(menuElement, 'mouseleave', SUB_ELEMENTS, toggleSubMenu); | ||
on(menuElement, 'mouseenter', SUB_ELEMENTS, toggleSubMenu); | ||
on(menuElement, 'mouseleave', SUB_ELEMENTS, toggleSubMenu); | ||
} | ||
|
||
return { | ||
init | ||
} | ||
} | ||
|
||
export default useTopMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters