fix(autocomplete): panel direction not being updated if the trigger direction changes (#10916)

This commit is contained in:
Kristiyan Kostadinov
2018-05-01 10:47:37 -04:00
committed by Joey Perrott
parent 422d1024b4
commit 8c30cee5f4
2 changed files with 31 additions and 2 deletions
+7 -2
View File
@@ -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()) {
@@ -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()
});
}
@@ -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;
}
+24
View File
@@ -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;