Skip to content

Commit

Permalink
fix(core/menu): close overlays if menu item is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
danielleroux committed Nov 4, 2022
1 parent 39ff691 commit 59b5fe4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8626,4 +8626,4 @@
"listeners": []
}
]
}
}
8 changes: 0 additions & 8 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2578,10 +2578,6 @@ declare namespace LocalJSX {
* Map Sidebar expanded
*/
"onMapExpandChange"?: (event: CustomEvent<boolean>) => void;
/**
* Event to emit to parent that the item was selected
*/
"onOverlayClose"?: (event: CustomEvent<boolean>) => void;
/**
* Is about tab visible
*/
Expand Down Expand Up @@ -2696,10 +2692,6 @@ declare namespace LocalJSX {
* Show notification cound on tab
*/
"notifications"?: number;
/**
* Event to emit to parent that the item was selected
*/
"onOnClick"?: (event: CustomEvent<boolean>) => void;
/**
* Icon name from @siemens/ix-icons
*/
Expand Down
12 changes: 1 addition & 11 deletions packages/core/src/components/menu-item/menu-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* LICENSE file in the root directory of this source tree.
*/

import { Component, Element, h, Host, Prop, State, Event, EventEmitter } from '@stencil/core';
import { Component, Element, h, Host, Prop, State } from '@stencil/core';

@Component({
tag: 'ix-menu-item',
Expand Down Expand Up @@ -49,11 +49,6 @@ export class MenuItem {

@State() title: string;

/**
* Event to emit to parent that the item was selected
*/
@Event() onClick: EventEmitter<boolean>;

get tabLabel() {
return this.hostElement.querySelector('.tab-text');
}
Expand All @@ -66,14 +61,9 @@ export class MenuItem {
}
}

private clicked = () => {
this.onClick.emit(true)
}

render() {
return (
<Host
onClick={this.clicked}
class={{
disabled: this.disabled,
'home-tab': this.home,
Expand Down
31 changes: 17 additions & 14 deletions packages/core/src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,6 @@ export class Menu {

@State() isMoreTabEmpty = false;

/**
* Event to emit to parent that the item was selected
*/
@Event() overlayClose: EventEmitter<boolean>;

@Listen('onClick',{target: "body"})
closeMenu(event: CustomEvent) {
if(event.detail === true){
this.expand = false;
this.overlayClose.emit(true)
}
}

private readonly domObserver = new MutationObserver(
this.onDomChange.bind(this)
);
Expand Down Expand Up @@ -671,7 +658,19 @@ export class Menu {
return this.mapExpand ? 'double-chevron-left' : 'double-chevron-right';
}

private closeOverlay(event: MouseEvent) {
const path = event.composedPath();
const shouldCloseOverlay = path.some((element: HTMLElement) => {
if (element.tagName !== 'IX-MENU-ITEM') {
return false;
}

if (!element.id) {
return true;
}
});
return shouldCloseOverlay;
}

render() {
return (
Expand All @@ -685,8 +684,11 @@ export class Menu {
menu: true,
expanded: this.expand,
}}
onClick={() => {
onClick={(event) => {
this.resetActiveTab();
if (this.closeOverlay(event)) {
this.resetOverlay();
}
}}
>
<div
Expand Down Expand Up @@ -778,6 +780,7 @@ export class Menu {
<div class="bottom-tab-divider"></div>
{this.enableSettings && !this.isSettingsEmpty ? (
<ix-menu-item
id="settings"
class={{
'internal-tab': true,
'bottom-tab': true,
Expand Down

0 comments on commit 59b5fe4

Please sign in to comment.