Skip to content
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
9 changes: 7 additions & 2 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,9 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
});
}
} else {
/** Update the panel width, in case the host width has changed */
// Update the panel width and direction, in case anything has changed.
this._overlayRef.updateSize({width: this._getHostWidth()});
this._overlayRef.setDirection(this._getDirection());
}

if (this._overlayRef && !this._overlayRef.hasAttached()) {
Expand All @@ -524,7 +525,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
positionStrategy: this._getOverlayPosition(),
scrollStrategy: this._scrollStrategy(),
width: this._getHostWidth(),
direction: this._dir ? this._dir.value : 'ltr'
direction: this._getDirection()
});
}

Expand All @@ -541,6 +542,10 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
return this._positionStrategy;
}

private _getDirection() {
return this._dir ? this._dir.value : 'ltr';
}

private _getConnectedElement(): ElementRef {
return this._formField ? this._formField.getConnectedOverlayOrigin() : this._element;
}
Expand Down
24 changes: 24 additions & 0 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,30 @@ describe('MatAutocomplete', () => {
expect(overlayPane.getAttribute('dir')).toEqual('rtl');
});

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

rtlFixture.detectChanges();
rtlFixture.componentInstance.trigger.openPanel();
rtlFixture.detectChanges();

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

rtlFixture.componentInstance.trigger.closePanel();
rtlFixture.detectChanges();

dirProvider.value = 'ltr';
rtlFixture.componentInstance.trigger.openPanel();
rtlFixture.detectChanges();

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

describe('forms integration', () => {
let fixture: ComponentFixture<SimpleAutocomplete>;
let input: HTMLInputElement;
Expand Down