Skip to content

Commit 0029cde

Browse files
crisbetojelbourn
authored andcommittedFeb 20, 2019
fix(bidi): handle uppercase values correctly (#14773)
The native `dir` attribute is case-insensitive, however our `dir` directive will normalize something like `RTL` to `ltr`. These changes account for different cases of the values.
1 parent edf4541 commit 0029cde

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
 

‎src/cdk/bidi/dir.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ export class Dir implements Directionality, AfterContentInit, OnDestroy {
4747
get dir(): Direction { return this._dir; }
4848
set dir(value: Direction) {
4949
const old = this._dir;
50+
const normalizedValue = value ? value.toLowerCase() : value;
5051

5152
this._rawDir = value;
52-
this._dir = (value === 'ltr' || value === 'rtl') ? value : 'ltr';
53+
this._dir = (normalizedValue === 'ltr' || normalizedValue === 'rtl') ? normalizedValue : 'ltr';
5354

5455
if (old !== this._dir && this._isInitialized) {
5556
this.change.emit(this._dir);

‎src/cdk/bidi/directionality.spec.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ describe('Directionality', () => {
1111

1212
TestBed.configureTestingModule({
1313
imports: [BidiModule],
14-
declarations: [ElementWithDir, ElementWithPredefinedAutoDir, InjectsDirectionality],
14+
declarations: [
15+
ElementWithDir,
16+
ElementWithPredefinedAutoDir,
17+
InjectsDirectionality,
18+
ElementWithPredefinedUppercaseDir,
19+
],
1520
providers: [{provide: DIR_DOCUMENT, useFactory: () => fakeDocument}],
1621
}).compileComponents();
1722
}));
@@ -134,6 +139,13 @@ describe('Directionality', () => {
134139
expect(fixture.componentInstance.dir.value).toBe('ltr');
135140
});
136141

142+
it('should be case-insensitive', () => {
143+
const fixture = TestBed.createComponent(ElementWithPredefinedUppercaseDir);
144+
fixture.detectChanges();
145+
146+
expect(fixture.componentInstance.dir.value).toBe('rtl');
147+
});
148+
137149
});
138150
});
139151

@@ -158,6 +170,14 @@ class ElementWithPredefinedAutoDir {
158170
@ViewChild(Dir) dir: Dir;
159171
}
160172

173+
@Component({
174+
template: '<div dir="RTL"></div>'
175+
})
176+
class ElementWithPredefinedUppercaseDir {
177+
@ViewChild(Dir) dir: Dir;
178+
}
179+
180+
161181
/** Test component with Dir directive. */
162182
@Component({
163183
selector: 'injects-directionality',

0 commit comments

Comments
 (0)
Please sign in to comment.