Skip to content

Conversation

@EladBezalel
Copy link
Member

fixes #4387

@EladBezalel EladBezalel requested a review from jelbourn July 2, 2017 16:30
@parker-mike
Copy link

@EladBezalel Can you please elaborate or prepare a plnkr on how to change the direction of the document from the code, since when I import Directionality out of @angular/cdk and inject it into the constructor of the app component, I can read the value, but when I set it to "rtl" nothing happens, not even the change is being emitted.

# Angular Material bi-directionality

### How to set your application direction
The simplest way is applying `dir` attribute on either the `html` or `body` tags.
Copy link
Member

@jelbourn jelbourn Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this as more...

### 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;
    });
  }
}
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jelbourn

It will not emit for changes to dir on <html> and <body>, as these are assumed to be static.

I'm not sure that this is a correct assumption to make, since overlayed items(div.cdk-overlay-container) are generated outside the Angular application context, so we don't have a single point to change the layout of the application. Or may be I have something missed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This describes the behavior right now. It could potentially change in a subsequent iteration.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jelbourn So, perhaps it could be a bright idea to specify that this is something to be revised. Should I open a feature request for this?

@EladBezalel EladBezalel force-pushed the docs/bidirectionality branch from 106d68e to 1cf4a7e Compare July 11, 2017 21:00
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 11, 2017
@EladBezalel EladBezalel force-pushed the docs/bidirectionality branch from 1cf4a7e to 33a1e01 Compare July 11, 2017 21:02
@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jul 11, 2017
Copy link

@zoharyosef zoharyosef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RTL documentation missing

5 participants