Skip to content

whitelist open attribute for <details/> in attribute selector #5425

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 3 commits into from
Sep 18, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Support `use:obj.method` as actions ([#3935](https://github.com/sveltejs/svelte/issues/3935))
* Support `_` as numeric separator ([#5407](https://github.com/sveltejs/svelte/issues/5407))
* Fix assignments to properties on store values ([#5412](https://github.com/sveltejs/svelte/issues/5412))
* Add special style scoping handling of `[open]` selectors on `<details>` elements ([#5421](https://github.com/sveltejs/svelte/issues/5421))
* Support `import.meta` in template expressions ([#5422](https://github.com/sveltejs/svelte/issues/5422))

## 3.25.1
Expand Down
10 changes: 9 additions & 1 deletion src/compiler/compile/css/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ enum BlockAppliesToNode {
UnknownSelectorType
}

const whitelist_attribute_selector = new Map([
['details', new Set(['open'])]
]);

export default class Selector {
node: CssNode;
stylesheet: Stylesheet;
Expand Down Expand Up @@ -232,7 +236,11 @@ function block_might_apply_to_node(block: Block, node: Element): BlockAppliesToN
}

else if (selector.type === 'AttributeSelector') {
if (!attribute_matches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags)) return BlockAppliesToNode.NotPossible;
if (
!(whitelist_attribute_selector.has(node.name.toLowerCase()) && whitelist_attribute_selector.get(node.name.toLowerCase()).has(selector.name.name.toLowerCase())) &&
!attribute_matches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags)) {
return BlockAppliesToNode.NotPossible;
}
}

else if (selector.type === 'TypeSelector') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
details[open].svelte-xyz{color:red}
7 changes: 7 additions & 0 deletions test/css/samples/attribute-selector-details-open/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<details>Hello</details>

<style>
details[open] {
color: red;
}
</style>