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
2 changes: 1 addition & 1 deletion src/material/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ export class MatFormField extends _MatFormFieldMixinBase
for (const child of labelEl.children) {
labelWidth += child.offsetWidth;
}
startWidth = labelStart - containerStart - outlineGapPadding;
startWidth = Math.abs(labelStart - containerStart) - outlineGapPadding;
gapWidth = labelWidth > 0 ? labelWidth * floatingLabelScale + outlineGapPadding * 2 : 0;
}

Expand Down
22 changes: 22 additions & 0 deletions src/material/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,28 @@ describe('MatInput with appearance', () => {
expect(parseInt(outlineGap.style.width)).toBeGreaterThan(0);
}));

it('should calculate the gap when starting off in RTL', fakeAsync(() => {
fixture.destroy();
TestBed.resetTestingModule();

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

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

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

expect(parseInt(outlineStart.style.width)).toBeGreaterThan(0);
expect(parseInt(outlineGap.style.width)).toBeGreaterThan(0);
}));

it('should not set an outline gap if the label is empty', fakeAsync(() => {
fixture.destroy();
TestBed.resetTestingModule();
Expand Down