mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(autocomplete): panel direction not being updated if the trigger direction changes (#10916)
This commit is contained in:
committed by
Joey Perrott
parent
422d1024b4
commit
8c30cee5f4
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user