Skip to content

fix(menu): remove classes from inert element #4800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TemplateRef,
ViewChild,
ViewEncapsulation,
ElementRef,
} from '@angular/core';
import {MenuPositionX, MenuPositionY} from './menu-positions';
import {throwMdMenuInvalidPositionX, throwMdMenuInvalidPositionY} from './menu-errors';
Expand Down Expand Up @@ -85,16 +86,22 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
*/
@Input('class')
set classList(classes: string) {
this._classList = classes.split(' ').reduce((obj: any, className: string) => {
obj[className] = true;
return obj;
}, {});
this.setPositionClasses();
if (classes && classes.length) {
this._classList = classes.split(' ').reduce((obj: any, className: string) => {
obj[className] = true;
return obj;
}, {});

this._elementRef.nativeElement.className = '';
this.setPositionClasses();
}
}

/** Event emitted when the menu is closed. */
@Output() close = new EventEmitter<void>();

constructor(private _elementRef: ElementRef) { }

ngAfterContentInit() {
this._keyManager = new FocusKeyManager(this.items).withWrap();
this._tabSubscription = this._keyManager.tabOut.subscribe(() => this._emitCloseEvent());
Expand Down
18 changes: 17 additions & 1 deletion src/lib/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ describe('MdMenu', () => {
expect(overlayPane.getAttribute('dir')).toEqual('rtl');
});

it('should transfer any custom classes from the host to the overlay', () => {
const fixture = TestBed.createComponent(SimpleMenu);

fixture.detectChanges();
fixture.componentInstance.trigger.openMenu();

const menuEl = fixture.debugElement.query(By.css('md-menu')).nativeElement;
const panel = overlayContainerElement.querySelector('.mat-menu-panel');

expect(menuEl.classList).not.toContain('custom-one');
expect(menuEl.classList).not.toContain('custom-two');

expect(panel.classList).toContain('custom-one');
expect(panel.classList).toContain('custom-two');
});

describe('positions', () => {
let fixture: ComponentFixture<PositionedMenu>;
let panel: HTMLElement;
Expand Down Expand Up @@ -462,7 +478,7 @@ describe('MdMenu', () => {
@Component({
template: `
<button [mdMenuTriggerFor]="menu" #triggerEl>Toggle menu</button>
<md-menu #menu="mdMenu" (close)="closeCallback()">
<md-menu class="custom-one custom-two" #menu="mdMenu" (close)="closeCallback()">
<button md-menu-item> Item </button>
<button md-menu-item disabled> Disabled </button>
</md-menu>
Expand Down