Skip to content
Snippets Groups Projects
Commit ec926c9e authored by druid's avatar druid
Browse files

Merge branch 'NXSTAGE-1000-upper-navigation' of...

Merge branch 'NXSTAGE-1000-upper-navigation' of version.helsinki.fi:julkiset-sivut/design-system-lib into NXSTAGE-1000-upper-navigation

merging
parents e532ef29 0c0177d9
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ export interface DesktopLinks { ...@@ -16,7 +16,7 @@ export interface DesktopLinks {
} }
import {ColorVariant} from '../../../utils/utils'; import {ColorVariant} from '../../../utils/utils';
import {Component, h, Element, Listen, Prop, State, Watch} from '@stencil/core'; import {Component, h, Element, Prop, State, Watch} from '@stencil/core';
@Component({ @Component({
tag: 'hy-desktop-menu-links', tag: 'hy-desktop-menu-links',
...@@ -44,25 +44,23 @@ export class HyDesktopMenuLinks { ...@@ -44,25 +44,23 @@ export class HyDesktopMenuLinks {
handleDesktopMenuClose() { handleDesktopMenuClose() {
const menuItems = this.el.shadowRoot.querySelectorAll(`.desktop-menu-link`); const menuItems = this.el.shadowRoot.querySelectorAll(`.desktop-menu-link`);
const menuPanelItems = this.el.shadowRoot.querySelectorAll('.hy-desktop-menu-panel'); const menuPanelItems = this.el.shadowRoot.querySelectorAll('.hy-desktop-menu-panel');
const activeMenuItem = this.el.shadowRoot.querySelector(`.desktop-menu-link[aria-expanded="true"]`);
// Return focus to the button of the last desktop panel that was active.
if (activeMenuItem !== null) (activeMenuItem as HTMLElement).focus();
// Reset elements by removing the active classes. // Reset elements by removing the active classes.
menuItems.forEach((item) => { menuItems.forEach((item) => {
item.classList.remove('desktop-menu-link--is-active'); item.classList.remove('desktop-menu-link--is-active');
item.setAttribute('aria-expanded', 'false');
}); });
menuPanelItems.forEach((item) => { menuPanelItems.forEach((item) => {
item.classList.remove('hy-desktop-menu-panel--is-active'); item.classList.remove('hy-desktop-menu-panel--is-active');
item.setAttribute('aria-hidden', 'true');
}); });
} }
@Listen('click')
handleMenuDesktopLinkClick(event) {
this.handleDesktopMenuClose();
event.stopPropagation();
}
handleDesktopMenuToggle(id) { handleDesktopMenuToggle(id) {
console.log(id);
const menuItems = this.el.shadowRoot.querySelectorAll(`.desktop-menu-link`); const menuItems = this.el.shadowRoot.querySelectorAll(`.desktop-menu-link`);
const menuPanelItems = this.el.shadowRoot.querySelectorAll('.hy-desktop-menu-panel'); // all panels const menuPanelItems = this.el.shadowRoot.querySelectorAll('.hy-desktop-menu-panel'); // all panels
const activeMenuItem = this.el.shadowRoot.querySelector(`.desktop-menu-link[link-id="${id}"]`); const activeMenuItem = this.el.shadowRoot.querySelector(`.desktop-menu-link[link-id="${id}"]`);
...@@ -71,14 +69,18 @@ export class HyDesktopMenuLinks { ...@@ -71,14 +69,18 @@ export class HyDesktopMenuLinks {
// Reset elements by removing the active classes. // Reset elements by removing the active classes.
menuItems.forEach((item) => { menuItems.forEach((item) => {
item.classList.remove('desktop-menu-link--is-active'); item.classList.remove('desktop-menu-link--is-active');
item.setAttribute('aria-expanded', 'false');
}); });
menuPanelItems.forEach((item) => { menuPanelItems.forEach((item) => {
item.classList.remove('hy-desktop-menu-panel--is-active'); item.classList.remove('hy-desktop-menu-panel--is-active');
item.setAttribute('aria-hidden', 'true');
}); });
// Add active classes to the currently active item and its sibling element. // Add active classes to the currently active item and its sibling element.
activeMenuItem.classList.add('desktop-menu-link--is-active'); activeMenuItem.classList.add('desktop-menu-link--is-active');
activeMenuItem.setAttribute('aria-expanded', 'true');
activeMenuItemSibling.classList.add('hy-desktop-menu-panel--is-active'); activeMenuItemSibling.classList.add('hy-desktop-menu-panel--is-active');
activeMenuItemSibling.setAttribute('aria-hidden', 'false');
} }
componentDidLoad() { componentDidLoad() {
...@@ -99,13 +101,14 @@ export class HyDesktopMenuLinks { ...@@ -99,13 +101,14 @@ export class HyDesktopMenuLinks {
link-id={id} link-id={id}
onMouseOver={() => this.handleDesktopMenuToggle(id)} onMouseOver={() => this.handleDesktopMenuToggle(id)}
onFocus={() => this.handleDesktopMenuToggle(id)} onFocus={() => this.handleDesktopMenuToggle(id)}
aria-expanded="false"
> >
{label} {label}
<span class="desktop-menu-link__heading__icon"> <span class="desktop-menu-link__heading__icon">
<hy-icon icon={'hy-icon-caret-down'} size={16} /> <hy-icon icon={'hy-icon-caret-down'} size={16} />
</span> </span>
</button> </button>
<div class="hy-desktop-menu-panel" onMouseLeave={() => this.handleDesktopMenuClose()}> <div class="hy-desktop-menu-panel" onMouseLeave={() => this.handleDesktopMenuClose()} aria-hidden="true">
<div class="hy-desktop-menu-panel__desktop-menu"> <div class="hy-desktop-menu-panel__desktop-menu">
<div class="hy-desktop-menu-panel__desktop-menu__menu-items"> <div class="hy-desktop-menu-panel__desktop-menu__menu-items">
<a <a
...@@ -169,7 +172,7 @@ export class HyDesktopMenuLinks { ...@@ -169,7 +172,7 @@ export class HyDesktopMenuLinks {
class={{ class={{
'hy-desktop-menu-panel__panel-toggle': true, 'hy-desktop-menu-panel__panel-toggle': true,
}} }}
aria-label="close" aria-label="Close menu"
> >
<span class="hy-desktop-menu-panel__panel-toggle__label"> <span class="hy-desktop-menu-panel__panel-toggle__label">
<span class="hy-desktop-menu-panel__panel-toggle__label__title">CLOSE</span> <span class="hy-desktop-menu-panel__panel-toggle__label__title">CLOSE</span>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment