Skip to content

Commit 294ba3c

Browse files
crisbetojosephperrott
authored andcommitted
fix(menu): not updating panel direction after init (#11070)
1 parent 3f5e481 commit 294ba3c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/lib/menu/menu-trigger.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
195195
return;
196196
}
197197

198-
this._createOverlay().attach(this._portal);
198+
const overlayRef = this._createOverlay();
199+
overlayRef.setDirection(this.dir);
200+
overlayRef.attach(this._portal);
199201

200202
if (this.menu.lazyContent) {
201203
this.menu.lazyContent.attach(this.menuData);
@@ -344,7 +346,6 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
344346
positionStrategy: this._getPosition(),
345347
hasBackdrop: this.menu.hasBackdrop == null ? !this.triggersSubmenu() : this.menu.hasBackdrop,
346348
backdropClass: this.menu.backdropClass || 'cdk-overlay-transparent-backdrop',
347-
direction: this.dir,
348349
scrollStrategy: this._scrollStrategy()
349350
});
350351
}

src/lib/menu/menu.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,30 @@ describe('MatMenu', () => {
245245
expect(overlayPane.getAttribute('dir')).toEqual('rtl');
246246
});
247247

248+
it('should update the panel direction if the trigger direction changes', () => {
249+
const dirProvider = {value: 'rtl'};
250+
const fixture = createComponent(SimpleMenu, [{
251+
provide: Directionality, useFactory: () => dirProvider}
252+
], [FakeIcon]);
253+
254+
fixture.detectChanges();
255+
fixture.componentInstance.trigger.openMenu();
256+
fixture.detectChanges();
257+
258+
let overlayPane = overlayContainerElement.querySelector('.cdk-overlay-pane')!;
259+
expect(overlayPane.getAttribute('dir')).toEqual('rtl');
260+
261+
fixture.componentInstance.trigger.closeMenu();
262+
fixture.detectChanges();
263+
264+
dirProvider.value = 'ltr';
265+
fixture.componentInstance.trigger.openMenu();
266+
fixture.detectChanges();
267+
268+
overlayPane = overlayContainerElement.querySelector('.cdk-overlay-pane')!;
269+
expect(overlayPane.getAttribute('dir')).toEqual('ltr');
270+
});
271+
248272
it('should transfer any custom classes from the host to the overlay', () => {
249273
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
250274

0 commit comments

Comments
 (0)