Skip to content

Fix :dir selectors with nested custom elements #4970

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

Merged
merged 2 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/mixins/dir-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
const HOST_DIR = /:host\(:dir\((ltr|rtl)\)\)/g;
const HOST_DIR_REPLACMENT = ':host([dir="$1"])';

const EL_DIR = /([\s\w#\.\[\]\*]*):dir\((ltr|rtl)\)/g;
const EL_DIR = /([\s\w-#\.\[\]\*]*):dir\((ltr|rtl)\)/g;
const EL_DIR_REPLACMENT = ':host([dir="$2"]) $1';

/**
Expand Down
56 changes: 56 additions & 0 deletions test/unit/dir.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,54 @@
</template>
</test-fixture>

<script>
addEventListener('WebComponentsReady', () => {
class OtherElement extends Polymer.Element {}
customElements.define('other-element', OtherElement);
});
</script>

<dom-module id="x-complicated">
<template>
<style>
#direct:dir(rtl) {
border: 10px solid black;
}
:dir(rtl) #indirect {
border: 9px solid black;
}
other-element:dir(rtl) {
border: 8px solid black;
}
#container:dir(rtl) ::slotted(*) {
border: 7px solid black;
}
</style>
<div id="direct"></div>
<div id="indirect"></div>
<other-element id="other"></other-element>
<div id="container">
<slot></slot>
</div>
</template>
<script>
addEventListener('WebComponentsReady', () => {
class XComplicated extends Polymer.DirMixin(Polymer.Element) {
static get is() {return 'x-complicated';}
}
customElements.define(XComplicated.is, XComplicated);
});
</script>
</dom-module>

<test-fixture id="complicated">
<template>
<x-complicated>
<div></div>
</x-complicated>
</template>
</test-fixture>

<script>
function assertComputed(node, expected, property = 'border-top-width') {
let actual = getComputedStyle(node).getPropertyValue(property).trim();
Expand Down Expand Up @@ -195,6 +243,14 @@
let el = fixture('legacy');
assertComputed(el, '2px');
});

test('complicated setup', function() {
let el = fixture('complicated');
assertComputed(el.$.direct, '10px');
assertComputed(el.$.indirect, '9px');
assertComputed(el.$.other, '8px');
assertComputed(el.firstElementChild, '7px');
});
});
</script>
</body>
Expand Down