Skip to content

fix(form-field): FormField with outline doesn't work well with dir="r… #15415

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 46 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
501b6be
fix(form-field): FormField with outline doesn't work well with dir="r…
Suresh918 Mar 7, 2019
2dd29e0
Revert "fix(form-field): FormField with outline doesn't work well wit…
Suresh918 Mar 15, 2019
0013ac5
Merge branch 'master' of https://github.com/angular/material2 into di…
Suresh918 Mar 15, 2019
1ca5bce
fix(form-field): FormField with outline doesn't work well with dir="r…
Suresh918 Mar 15, 2019
63ca947
chore(ivy): add static flag to tab-related static queries
kara Feb 20, 2019
ba98344
chore(ivy): add static flag to dialog-related static queries (#15239)
kara Feb 20, 2019
d06b0bf
chore(ivy): add static flag to more queries (#15252)
kara Feb 20, 2019
cbd527c
chore(ivy): add static flag to tree-related static queries (#15255)
kara Feb 20, 2019
a22cbbb
chore(ivy): add static flag to table-related static queries (#15257)
kara Feb 21, 2019
2df2af2
chore(ivy): fix static query stragglers that were not marked static q…
kara Feb 21, 2019
050af72
test(menu): refactor test that depends on static queries (#15289)
crisbeto Feb 25, 2019
4e61755
test(sidenav): fix sidenav failures under Ivy (#15300)
crisbeto Feb 25, 2019
6adbdb2
test(overlay): use static queries w/ overlay containers (#15301)
jelbourn Feb 26, 2019
77c13c8
test(select): update static query tests (#15320)
crisbeto Feb 26, 2019
864b238
test(accordion): update static query test (#15357)
marclaval Mar 1, 2019
4f08d26
fix: mark virtual scroll viewport queries as static (#15346)
kara Mar 1, 2019
6743041
fix(form-field): FormField with outline doesn't work well with dir="r…
Suresh918 Mar 7, 2019
4338173
refactor(button): use [attr.disabled] host binding in MatButton (#15308)
jelbourn Mar 8, 2019
705211b
fix(list): override native button text align in action list (#15404)
mitchellwills Mar 8, 2019
5bbbfe3
fix(badge): duplicate leftover badge after server-side render (#15417)
crisbeto Mar 8, 2019
0b47031
chore: bump version to 7.3.4 w/ changelog (#15439)
josephperrott Mar 11, 2019
b07f20c
fix(schematics): do not run migrations multiple times (#15424)
devversion Mar 11, 2019
364cb97
docs(drag-drop): add docs and live example for disabled sorting (#15426)
crisbeto Mar 11, 2019
04cfbb1
test(chip-list): rework tests to work under Ivy (#15428)
crisbeto Mar 11, 2019
25bf0c2
build: throw error if example is missing a title (#15430)
crisbeto Mar 11, 2019
b0a17a1
refactor(selection-list): avoid deprecated method (#15393)
swseverance Mar 11, 2019
0f9f706
test(table): update static query test (#15452)
marclaval Mar 12, 2019
71ef456
refactor(stepper): rework buttons to handle Ivy (#15429)
crisbeto Mar 12, 2019
401173f
fix(table): use default change detection strategy on table (#15440)
andrewseguin Mar 12, 2019
e62d5d6
test(input): make the type validation test to pass in Ivy (#15460)
marclaval Mar 13, 2019
81a5ebf
fix(stepper): avoid breaking change in stepControl type (#15464)
crisbeto Mar 13, 2019
71b3949
fix(tooltip): render style values in ngOnInit instead of the construc…
matsko Mar 14, 2019
f63e725
chore: update tooltip golden file (#15479)
crisbeto Mar 14, 2019
eca118f
refactor(datepicker): adapt custom header demo for Ivy (#15458)
marclaval Mar 14, 2019
c6a51e7
refactor(focus-monitor): adapt demo examples for Ivy (#15475)
marclaval Mar 14, 2019
f9936ed
fix(table): use static queries for examples (#15483)
andrewseguin Mar 15, 2019
fc66e95
fix(stepper): content not being rendered out initially with ivy (#15485)
crisbeto Mar 15, 2019
aa735dd
Revert "fix(form-field): FormField with outline doesn't work well wit…
Suresh918 Mar 15, 2019
30805cb
fix(form-field): FormField with outline doesn't work well with dir="r…
Suresh918 Mar 15, 2019
f767f05
Merge branch 'directionality-update' of https://github.com/Suresh918/…
Suresh918 Apr 15, 2019
f7973dd
fix(form-field): test cases added for form field outline styles w.r.t…
Suresh918 Apr 15, 2019
b2e25a8
fix(form-field): lint errors and test cases fixes
Suresh918 Apr 15, 2019
9746c91
fix(form-field): lint errors and test cases fixes
Suresh918 Apr 15, 2019
c68824f
fix(form-field): test cases changes and comments added
Suresh918 Apr 15, 2019
7de5c7f
fix(form-field): lint error fix
Suresh918 Apr 15, 2019
08a7c28
Merge remote-tracking branch 'upstream/master' into pr15415
mmalerba Jun 26, 2019
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
18 changes: 15 additions & 3 deletions src/material/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directionality} from '@angular/cdk/bidi';
import {Direction, Directionality} from '@angular/cdk/bidi';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {
AfterContentChecked,
Expand Down Expand Up @@ -231,6 +231,15 @@ export class MatFormField extends _MatFormFieldMixinBase
/** Whether the Angular animations are enabled. */
_animationsEnabled: boolean;

/* Holds the previous direction emitted by directionality service change emitter.
This is used in updateOutlineGap() method to update the width and position of the gap in the
outline. Only relevant for the outline appearance. The direction is getting updated in the
UI after directionality service change emission. So the outlines gaps are getting
updated in updateOutlineGap() method before connectionContainer child direction change
in UI. We may get wrong calculations. So we are storing the previous direction to get the
correct outline calculations*/
private _previousDirection: Direction = 'ltr';

/**
* @deprecated
* @breaking-change 8.0.0
Expand Down Expand Up @@ -343,7 +352,10 @@ export class MatFormField extends _MatFormFieldMixinBase
});

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

Expand Down Expand Up @@ -565,6 +577,6 @@ export class MatFormField extends _MatFormFieldMixinBase

/** Gets the start end of the rect considering the current directionality. */
private _getStartEnd(rect: ClientRect): number {
return this._dir && this._dir.value === 'rtl' ? rect.right : rect.left;
return this._previousDirection === 'rtl' ? rect.right : rect.left;
}
}
55 changes: 55 additions & 0 deletions src/material/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,61 @@ describe('MatInput with appearance', () => {
expect(outlineFixture.componentInstance.formField.updateOutlineGap).toHaveBeenCalled();
}));

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

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

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

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

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

let wrapperElement = outlineFixture.nativeElement;
let outlineStart = wrapperElement.querySelector('.mat-form-field-outline-start');
// outlineGapPadding 5px + containerRect margin/padding in worst case 3px
const maxOutlineStart = '8px';

expect(outlineFixture.componentInstance.formField.updateOutlineGap).toHaveBeenCalled();
expect(parseInt(outlineStart.style.width)).toBeLessThan(parseInt(maxOutlineStart));

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

wrapperElement = outlineFixture.nativeElement;
outlineStart = wrapperElement.querySelector('.mat-form-field-outline-start');

expect(outlineFixture.componentInstance.formField.updateOutlineGap).toHaveBeenCalled();
expect(parseInt(outlineStart.style.width)).toBeLessThan(parseInt(maxOutlineStart));

}));




});
Expand Down