Skip to content

Commit bb316cb

Browse files
EladBezaleljelbourn
authored andcommitted
docs(bidi): add initial guide (#5474)
1 parent c479faa commit bb316cb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

guides/bidirectionality.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Angular Material bi-directionality
2+
3+
### Setting a text-direction for your application
4+
The [`dir` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)
5+
is typically applied to `<html>` or `<body>` element of a page. However, it can be used on any
6+
element to apply a text-direction to a smaller subset of the page.
7+
8+
All Angular Material components automatically reflect the LTR/RTL direction
9+
of their container.
10+
11+
### Reading the text-direction in your own components
12+
`@angular/cdk` provides a `Directionality` injectable that can be used by any component
13+
in your application. To consume this injectable, you must import `BidiModule`
14+
from `@angular/cdk`.
15+
16+
`Directionality` provides two useful properties:
17+
* `value`: the current text direction, either `'ltr'` or `'rtl'`.
18+
* `change`: an `Observable` that emits whenever the text-direction changes. Note that this only
19+
captures changes from `dir` attributes _inside the Angular application context_. It will not
20+
emit for changes to `dir` on `<html>` and `<body>`, as these are assumed to be static.
21+
22+
#### Example
23+
```ts
24+
@Component({ /* ... */})
25+
export class MyCustomComponent {
26+
private dir: Direction;
27+
28+
constructor(directionality: Directionality) {
29+
this.dir = directionality.value;
30+
directionality.change.subscribe(() => {
31+
this.dir = directionality.value;
32+
});
33+
}
34+
}
35+
```

0 commit comments

Comments
 (0)