Skip to content

fix(form-field): outline gap not being recalculated on direction changes #13478

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
Dec 6, 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
6 changes: 3 additions & 3 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {MatOption, MatOptionSelectionChange} from '@angular/material/core';
import {MatFormField, MatFormFieldModule} from '@angular/material/form-field';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {Observable, Subject, Subscription} from 'rxjs';
import {Observable, Subject, Subscription, EMPTY} from 'rxjs';
import {map, startWith} from 'rxjs/operators';
import {MatInputModule} from '../input/index';
import {
Expand Down Expand Up @@ -485,7 +485,7 @@ describe('MatAutocomplete', () => {

it('should have the correct text direction in RTL', () => {
const rtlFixture = createComponent(SimpleAutocomplete, [
{provide: Directionality, useFactory: () => ({value: 'rtl'})},
{provide: Directionality, useFactory: () => ({value: 'rtl', change: EMPTY})},
]);

rtlFixture.detectChanges();
Expand All @@ -498,7 +498,7 @@ describe('MatAutocomplete', () => {
});

it('should update the panel direction if it changes for the trigger', () => {
const dirProvider = {value: 'rtl'};
const dirProvider = {value: 'rtl', change: EMPTY};
const rtlFixture = createComponent(SimpleAutocomplete, [
{provide: Directionality, useFactory: () => dirProvider},
]);
Expand Down
5 changes: 5 additions & 0 deletions src/lib/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class MatFormField extends _MatFormFieldMixinBase

/** Whether the outline gap needs to be calculated next time the zone has stabilized. */
private _outlineGapCalculationNeededOnStable = false;

private _destroyed = new Subject<void>();

/** The form-field appearance style. */
Expand Down Expand Up @@ -325,6 +326,10 @@ export class MatFormField extends _MatFormFieldMixinBase
this._syncDescribedByIds();
this._changeDetectorRef.markForCheck();
});

if (this._dir) {
this._dir.change.pipe(takeUntil(this._destroyed)).subscribe(() => this.updateOutlineGap());
}
}

ngAfterContentChecked() {
Expand Down
1 change: 1 addition & 0 deletions src/lib/input/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ng_test_library(
"@angular//packages/forms",
"@angular//packages/platform-browser",
"@angular//packages/platform-browser/animations",
"//src/cdk/bidi",
"//src/cdk/platform",
"//src/cdk/testing",
"//src/lib/core",
Expand Down
30 changes: 30 additions & 0 deletions src/lib/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {By} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MatStepperModule} from '@angular/material/stepper';
import {MatTabsModule} from '@angular/material/tabs';
import {Directionality, Direction} from '@angular/cdk/bidi';
import {Subject} from 'rxjs';
import {MatInputModule, MatInput, MAT_INPUT_VALUE_ACCESSOR} from './index';
import {MatTextareaAutosize} from './autosize';

Expand Down Expand Up @@ -1391,6 +1393,34 @@ describe('MatInput with appearance', () => {
expect(parseInt(outlineGap.style.width)).toBeGreaterThan(0);
}));

it('should update the outline gap if the direction changes', fakeAsync(() => {
fixture.destroy();
TestBed.resetTestingModule();

const fakeDirectionality = {change: new Subject<Direction>(), value: 'ltr'};
const outlineFixture = createComponent(MatInputWithAppearanceAndLabel, [{
provide: Directionality,
useValue: fakeDirectionality
}]);

outlineFixture.componentInstance.appearance = 'outline';
outlineFixture.detectChanges();
flush();
outlineFixture.detectChanges();

spyOn(outlineFixture.componentInstance.formField, 'updateOutlineGap');

fakeDirectionality.value = 'rtl';
fakeDirectionality.change.next('rtl');
outlineFixture.detectChanges();
flush();
outlineFixture.detectChanges();

expect(outlineFixture.componentInstance.formField.updateOutlineGap).toHaveBeenCalled();
}));



});

describe('MatFormField default options', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
import {MatFormFieldModule} from '@angular/material/form-field';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {Subject, Subscription} from 'rxjs';
import {Subject, Subscription, EMPTY, Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {MatSelectModule} from './index';
import {MatSelect} from './select';
Expand All @@ -76,7 +76,7 @@ const LETTER_KEY_DEBOUNCE_INTERVAL = 200;
describe('MatSelect', () => {
let overlayContainer: OverlayContainer;
let overlayContainerElement: HTMLElement;
let dir: {value: 'ltr'|'rtl'};
let dir: {value: 'ltr'|'rtl', change: Observable<string>};
let scrolledSubject = new Subject();
let viewportRuler: ViewportRuler;
let platform: Platform;
Expand All @@ -98,7 +98,7 @@ describe('MatSelect', () => {
],
declarations: declarations,
providers: [
{provide: Directionality, useFactory: () => dir = {value: 'ltr'}},
{provide: Directionality, useFactory: () => dir = {value: 'ltr', change: EMPTY}},
{
provide: ScrollDispatcher, useFactory: () => ({
scrolled: () => scrolledSubject.asObservable(),
Expand Down