Skip to content

Commit

Permalink
Fix :dir selectors with nested custom elements
Browse files Browse the repository at this point in the history
Fixes #4966
  • Loading branch information
dfreedm committed Dec 4, 2017
1 parent 1fbb504 commit 3b76e86
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
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

0 comments on commit 3b76e86

Please sign in to comment.