Skip to content

Commit 3b76e86

Browse files
committed
Fix :dir selectors with nested custom elements
Fixes #4966
1 parent 1fbb504 commit 3b76e86

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

lib/mixins/dir-mixin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
const HOST_DIR = /:host\(:dir\((ltr|rtl)\)\)/g;
1717
const HOST_DIR_REPLACMENT = ':host([dir="$1"])';
1818

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

2222
/**

test/unit/dir.html

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,54 @@
131131
</template>
132132
</test-fixture>
133133

134+
<script>
135+
addEventListener('WebComponentsReady', () => {
136+
class OtherElement extends Polymer.Element {}
137+
customElements.define('other-element', OtherElement);
138+
});
139+
</script>
140+
141+
<dom-module id="x-complicated">
142+
<template>
143+
<style>
144+
#direct:dir(rtl) {
145+
border: 10px solid black;
146+
}
147+
:dir(rtl) #indirect {
148+
border: 9px solid black;
149+
}
150+
other-element:dir(rtl) {
151+
border: 8px solid black;
152+
}
153+
#container:dir(rtl) ::slotted(*) {
154+
border: 7px solid black;
155+
}
156+
</style>
157+
<div id="direct"></div>
158+
<div id="indirect"></div>
159+
<other-element id="other"></other-element>
160+
<div id="container">
161+
<slot></slot>
162+
</div>
163+
</template>
164+
<script>
165+
addEventListener('WebComponentsReady', () => {
166+
class XComplicated extends Polymer.DirMixin(Polymer.Element) {
167+
static get is() {return 'x-complicated'}
168+
}
169+
customElements.define(XComplicated.is, XComplicated);
170+
})
171+
</script>
172+
</dom-module>
173+
174+
<test-fixture id="complicated">
175+
<template>
176+
<x-complicated>
177+
<div></div>
178+
</x-complicated>
179+
</template>
180+
</test-fixture>
181+
134182
<script>
135183
function assertComputed(node, expected, property = 'border-top-width') {
136184
let actual = getComputedStyle(node).getPropertyValue(property).trim();
@@ -195,6 +243,14 @@
195243
let el = fixture('legacy');
196244
assertComputed(el, '2px');
197245
});
246+
247+
test('complicated setup', function() {
248+
let el = fixture('complicated');
249+
assertComputed(el.$.direct, '10px');
250+
assertComputed(el.$.indirect, '9px');
251+
assertComputed(el.$.other, '8px');
252+
assertComputed(el.firstElementChild, '7px');
253+
});
198254
});
199255
</script>
200256
</body>

0 commit comments

Comments
 (0)