Skip to content
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

docs(bidirectionality): bidirectionality how-to explanation #5474

Merged
merged 1 commit into from
Jul 13, 2017
Merged
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
35 changes: 35 additions & 0 deletions guides/bidirectionality.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Angular Material bi-directionality

### Setting a text-direction for your application
The [`dir` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir)
is typically applied to `<html>` or `<body>` element of a page. However, it can be used on any
element to apply a text-direction to a smaller subset of the page.

All Angular Material components automatically reflect the LTR/RTL direction
of their container.

### Reading the text-direction in your own components
`@angular/cdk` provides a `Directionality` injectable that can be used by any component
in your application. To consume this injectable, you must import `BidiModule`
from `@angular/cdk`.

`Directionality` provides two useful properties:
* `value`: the current text direction, either `'ltr'` or `'rtl'`.
* `change`: an `Observable` that emits whenever the text-direction changes. Note that this only
captures changes from `dir` attributes _inside the Angular application context_. It will not
emit for changes to `dir` on `<html>` and `<body>`, as these are assumed to be static.

#### Example
```ts
@Component({ /* ... */})
export class MyCustomComponent {
private dir: Direction;

constructor(directionality: Directionality) {
this.dir = directionality.value;
directionality.change.subscribe(() => {
this.dir = directionality.value;
});
}
}
```