Skip to content

fix(menu): not updating panel direction after init #11070

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
May 1, 2018
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
5 changes: 3 additions & 2 deletions src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
return;
}

this._createOverlay().attach(this._portal);
const overlayRef = this._createOverlay();
overlayRef.setDirection(this.dir);
overlayRef.attach(this._portal);

if (this.menu.lazyContent) {
this.menu.lazyContent.attach(this.menuData);
Expand Down Expand Up @@ -344,7 +346,6 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
positionStrategy: this._getPosition(),
hasBackdrop: this.menu.hasBackdrop == null ? !this.triggersSubmenu() : this.menu.hasBackdrop,
backdropClass: this.menu.backdropClass || 'cdk-overlay-transparent-backdrop',
direction: this.dir,
scrollStrategy: this._scrollStrategy()
});
}
Expand Down
24 changes: 24 additions & 0 deletions src/lib/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,30 @@ describe('MatMenu', () => {
expect(overlayPane.getAttribute('dir')).toEqual('rtl');
});

it('should update the panel direction if the trigger direction changes', () => {
const dirProvider = {value: 'rtl'};
const fixture = createComponent(SimpleMenu, [{
provide: Directionality, useFactory: () => dirProvider}
], [FakeIcon]);

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

let overlayPane = overlayContainerElement.querySelector('.cdk-overlay-pane')!;
expect(overlayPane.getAttribute('dir')).toEqual('rtl');

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

dirProvider.value = 'ltr';
fixture.componentInstance.trigger.openMenu();
fixture.detectChanges();

overlayPane = overlayContainerElement.querySelector('.cdk-overlay-pane')!;
expect(overlayPane.getAttribute('dir')).toEqual('ltr');
});

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

Expand Down