Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit d9d4ff6

Browse files
author
Kate Jeffreys
committed
resurrect missing bits
1 parent 1ebff40 commit d9d4ff6

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

app/3.0/docs/devguide/style-shadow-dom.md

+102
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,108 @@ index.html { .caption }
492492

493493
[See it on Plunker](http://plnkr.co/edit/hR3I4w?p=preview)
494494

495+
### Style undefined elements
496+
497+
To avoid FOUC (flash of unstyled content), you might want to style custom elements before they are
498+
defined (that is, before the browser has attached their class definition to their markup tag). If
499+
you don't, the browser may not apply any styles to the element at first paint. Typically, you'll
500+
want to add styling for a few top-level elements so your application's layout displays while the
501+
element definitions are being loaded.
502+
503+
There is a specification for a `:defined` pseudo-class selector to target elements that have been
504+
defined, but the custom elements polyfill doesn't support this selector.
505+
506+
For a polyfill-friendly workaround, add an `unresolved` attribute to the element in markup. For
507+
example:
508+
509+
```html
510+
<my-element unresolved></my-element>
511+
```
512+
513+
Then style the unresolved element. For example:
514+
515+
```html
516+
<style>
517+
my-element[unresolved] {
518+
height: 45px;
519+
text-align: center;
520+
...
521+
}
522+
</style>
523+
```
524+
525+
Finally, remove the `unresolved` attribute in the element's `ready` callback:
526+
527+
```js
528+
class MyElement extends PolymerElement(){
529+
...
530+
ready(){
531+
super.ready();
532+
this.removeAttribute('unresolved');
533+
...
534+
}
535+
...
536+
}
537+
```
538+
539+
### Style directional text with the :dir() selector
540+
541+
The `:dir()` CSS selector allows for styling text specific to its orientation
542+
(right-to-left or left-to-right). See the [documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/:dir) for more information on the `:dir()`
543+
selector.
544+
545+
The `DirMixin` provides limited support for the `:dir()` selector. Use of `:dir()` requires the
546+
application to set the `dir` attribute on `<html>`. All elements will use the same direction.
547+
548+
Individual elements can opt-out of the global direction by setting the `dir` attribute
549+
in HTML or in the `ready` callback, but the text direction of these elements must from then on be handled
550+
manually.
551+
552+
Setting `dir` on an ancestor (other than `html`) has no effect.
553+
554+
For elements that extend `PolymerElement`, add `DirMixin` to use
555+
`:dir()` styling.
556+
557+
Here's an example use of the `:dir()` selector:
558+
559+
`using-dir-selector.js` { .caption }
560+
561+
```js
562+
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
563+
import DirMixin from '@polymer/polymer/lib/mixins/dir-mixin.js';
564+
565+
class UsingDirSelector extends DirMixin(PolymerElement) {
566+
static get template() {
567+
return html`
568+
<style>
569+
:host {
570+
display: block;
571+
color: blue;
572+
}
573+
:host(:dir(rtl)) {
574+
color: green;
575+
}
576+
</style>
577+
...
578+
`;
579+
}
580+
}
581+
customElements.define('using-dir-selector', UsingDirSelector);
582+
```
583+
584+
`index.html` { .caption }
585+
586+
```html
587+
<html lang="en" dir="rtl">
588+
<head>
589+
<script type="module" src="./using-dir-selector.js"></script>
590+
</head>
591+
<body>
592+
<using-dir-selector></using-dir-selector>
593+
</body>
594+
</html>
595+
```
596+
495597
## Share styles between elements
496598

497599
### Use style modules {#style-modules}

0 commit comments

Comments
 (0)