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
3 changes: 2 additions & 1 deletion src/cdk/bidi/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ export class Dir implements Directionality, AfterContentInit, OnDestroy {
get dir(): Direction { return this._dir; }
set dir(value: Direction) {
const old = this._dir;
const normalizedValue = value ? value.toLowerCase() : value;

this._rawDir = value;
this._dir = (value === 'ltr' || value === 'rtl') ? value : 'ltr';
this._dir = (normalizedValue === 'ltr' || normalizedValue === 'rtl') ? normalizedValue : 'ltr';

if (old !== this._dir && this._isInitialized) {
this.change.emit(this._dir);
Expand Down
22 changes: 21 additions & 1 deletion src/cdk/bidi/directionality.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ describe('Directionality', () => {

TestBed.configureTestingModule({
imports: [BidiModule],
declarations: [ElementWithDir, ElementWithPredefinedAutoDir, InjectsDirectionality],
declarations: [
ElementWithDir,
ElementWithPredefinedAutoDir,
InjectsDirectionality,
ElementWithPredefinedUppercaseDir,
],
providers: [{provide: DIR_DOCUMENT, useFactory: () => fakeDocument}],
}).compileComponents();
}));
Expand Down Expand Up @@ -134,6 +139,13 @@ describe('Directionality', () => {
expect(fixture.componentInstance.dir.value).toBe('ltr');
});

it('should be case-insensitive', () => {
const fixture = TestBed.createComponent(ElementWithPredefinedUppercaseDir);
fixture.detectChanges();

expect(fixture.componentInstance.dir.value).toBe('rtl');
});

});
});

Expand All @@ -158,6 +170,14 @@ class ElementWithPredefinedAutoDir {
@ViewChild(Dir) dir: Dir;
}

@Component({
template: '<div dir="RTL"></div>'
})
class ElementWithPredefinedUppercaseDir {
@ViewChild(Dir) dir: Dir;
}


/** Test component with Dir directive. */
@Component({
selector: 'injects-directionality',
Expand Down