Skip to content

Commit b5b02f8

Browse files
authored
whitelist [open] attribute selector for <details> (#5425)
1 parent 254096d commit b5b02f8

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Support `use:obj.method` as actions ([#3935](https://github.com/sveltejs/svelte/issues/3935))
66
* Support `_` as numeric separator ([#5407](https://github.com/sveltejs/svelte/issues/5407))
77
* Fix assignments to properties on store values ([#5412](https://github.com/sveltejs/svelte/issues/5412))
8+
* Add special style scoping handling of `[open]` selectors on `<details>` elements ([#5421](https://github.com/sveltejs/svelte/issues/5421))
89
* Support `import.meta` in template expressions ([#5422](https://github.com/sveltejs/svelte/issues/5422))
910

1011
## 3.25.1

src/compiler/compile/css/Selector.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ enum BlockAppliesToNode {
1111
UnknownSelectorType
1212
}
1313

14+
const whitelist_attribute_selector = new Map([
15+
['details', new Set(['open'])]
16+
]);
17+
1418
export default class Selector {
1519
node: CssNode;
1620
stylesheet: Stylesheet;
@@ -232,7 +236,11 @@ function block_might_apply_to_node(block: Block, node: Element): BlockAppliesToN
232236
}
233237

234238
else if (selector.type === 'AttributeSelector') {
235-
if (!attribute_matches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags)) return BlockAppliesToNode.NotPossible;
239+
if (
240+
!(whitelist_attribute_selector.has(node.name.toLowerCase()) && whitelist_attribute_selector.get(node.name.toLowerCase()).has(selector.name.name.toLowerCase())) &&
241+
!attribute_matches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags)) {
242+
return BlockAppliesToNode.NotPossible;
243+
}
236244
}
237245

238246
else if (selector.type === 'TypeSelector') {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
details[open].svelte-xyz{color:red}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<details>Hello</details>
2+
3+
<style>
4+
details[open] {
5+
color: red;
6+
}
7+
</style>

0 commit comments

Comments
 (0)