-
Notifications
You must be signed in to change notification settings - Fork 2k
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
:dir() support #4880
:dir() support #4880
Conversation
ShadyCSS version of the :dir transform is not good enough :(
Adapt scoped keyframes test for Safari 11 still failing on https://bugs.webkit.org/show_bug.cgi?id=166748
lib/mixins/dir-mixin.html
Outdated
function setRTL(instance) { | ||
if (!instance.__origRTLStatus) { | ||
const el = /** @type {!HTMLElement} */(instance); | ||
if (document.documentElement.getAttribute('dir') === 'rtl') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's capture this state so we can make this application function faster.
lib/mixins/dir-mixin.html
Outdated
* Element class mixin that allows elements to use the `:dir` CSS Selector to have | ||
* text direction specific styling. | ||
* | ||
* With this mixin, any stylesheet provided in the template will be transform `:dir` into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will transform
lib/mixins/dir-mixin.html
Outdated
* directly in `ready()`. | ||
* | ||
* Caveats: | ||
* - Automatic left-to-right or right-to-left styling is sync'd with the `<html>` element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<html>
element only, setting the dir attribute on an element further up the DOM tree will have no effect.
lib/mixins/dir-mixin.html
Outdated
* | ||
* Caveats: | ||
* - Automatic left-to-right or right-to-left styling is sync'd with the `<html>` element | ||
* - Applications must set `<html dir="ltr">` or `<html dir="rtl">` to sync direction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put this as the first caveat and then say that changing dir
on html is supported.
lib/mixins/dir-mixin.html
Outdated
* `:host([dir])` and sync direction with the page via the element's `dir` attribute. | ||
* | ||
* Elements can opt out of the global page text direction by setting the `dir` attribute | ||
* directly in `ready()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or in HTML?
lib/mixins/dir-mixin.html
Outdated
* @extends {base} | ||
* @implements {Polymer_ElementMixin} | ||
*/ | ||
const elementBase = Polymer.ElementMixin(base); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about removing this dependency and requiring users to at least also use PropertyAccessors?
lib/mixins/element-mixin.html
Outdated
finalizeTemplate(/** @type {!PolymerElement} */(this.__proto__), this._template, baseURI, | ||
/**@type {!HTMLElement}*/(this).localName); | ||
} | ||
this.constructor._finalizeTemplate(/** @type {!PolymerElement} */(this.__proto__), this._template, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a static now, let's not pass in the prototype.
* @override | ||
* @suppress {missingProperties} Interfaces in closure do not inherit statics, but classes do | ||
*/ | ||
static _processStyleText(is, template, baseURI) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's only enable the runtime element support if we find dir in the css.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/** | ||
* @suppress {invalidCasts} Closure doesn't understand that `this` is an HTMLElement | ||
*/ | ||
ready() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make these runtime features opt-in via a flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is still needed if we use the presence of :dir
to activate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok. They are different and an element could have either or both.
lib/mixins/dir-mixin.html
Outdated
* @appliesMixin Polymer.ElementMixin | ||
* @memberof Polymer | ||
*/ | ||
Polymer.DirMixin = Polymer.dedupingMixin((base) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's mix this into LegacyElement so we have hybrid support since 1.x has dir support now.
- Extend PropertyAccessors for greater flexibility - Detect if `:dir` is used in order to activate runtime features - Add to LegacyElement for 1.x compatibility - clean up `ElementMixin._finalizeTemplate`
lib/mixins/dir-mixin.html
Outdated
const DIR_INSTANCES = []; | ||
|
||
/** @type {MutationObserver} */ | ||
let OBSERVER = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not all caps for variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
/** | ||
* @suppress {invalidCasts} Closure doesn't understand that `this` is an HTMLElement | ||
*/ | ||
ready() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok. They are different and an element could have either or both.
lib/mixins/dir-mixin.html
Outdated
/** @suppress {missingProperties} Closure's understanding of prototypes is bad */ | ||
connectedCallback() { | ||
if (elementBase.prototype.connectedCallback) { | ||
/** @type {!Polymer_ElementMixin} */(elementBase).prototype.connectedCallback.call(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not super.connectedCallback()
(and same for disconnected...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PropertyAccessors doesn't have connectedCallback or disconnectedCallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically if you find it, call super.
rather than .call
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sure
lib/mixins/dir-mixin.html
Outdated
/** @type {!Polymer_ElementMixin} */(elementBase).prototype.connectedCallback.call(this); | ||
} | ||
if (this.constructor.__activateDir) { | ||
takeRecords(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this will fly (same in disconnected). We cannot update all elements as takeRecords does when one is connected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, just means I'll have to pull document direction on connected.
lib/mixins/dir-mixin.html
Outdated
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<link rel="import" href="../utils/style-gather.html"> | ||
<link rel="import" href="../utils/resolve-url.html"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem like the imports above are used, remove?
Reference Issue
Polymer 2.x fix for #4860
Goal
Allows for native and polyfilled ShadowDOM elements to use
:dir
CSS selector to provide text directionality based layouts.Details
Polymer.ElementMixin
to provide override points for stylesheet modification.dir
attribute directly inready()
.<html>
element<html dir="ltr">
or<html dir="rtl">
to sync direction