mirror of https://github.com/sveltejs/svelte
[feat] `|important` modifier for style directive (#7489)
* important modifier for style directive * docs * Exclude third param if false third param for set_style is optional * Remove unused test Runtime test doesn't work because of weird behaviour of computed style the puppeteer test should cover it * remove unnecessary test Co-authored-by: tanhauhau <lhtan93@gmail.com>pull/7942/head
parent
ff6e1c39d0
commit
bee1851faa
@ -0,0 +1 @@
|
||||
<div style:color|important={myColor}></div>
|
@ -0,0 +1,50 @@
|
||||
{
|
||||
"html": {
|
||||
"start": 0,
|
||||
"end": 43,
|
||||
"type": "Fragment",
|
||||
"children": [
|
||||
{
|
||||
"start": 0,
|
||||
"end": 43,
|
||||
"type": "Element",
|
||||
"name": "div",
|
||||
"attributes": [
|
||||
{
|
||||
"start": 5,
|
||||
"end": 36,
|
||||
"type": "StyleDirective",
|
||||
"name": "color",
|
||||
"modifiers": [
|
||||
"important"
|
||||
],
|
||||
"value": [
|
||||
{
|
||||
"start": 27,
|
||||
"end": 36,
|
||||
"type": "MustacheTag",
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start": 28,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 28
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 35
|
||||
}
|
||||
},
|
||||
"name": "myColor"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
export default {
|
||||
html: `
|
||||
<h1 class="svelte-szzkfu" style="background-color: red;">hello</h1>
|
||||
<h1 class="svelte-szzkfu" style="background-color: red !important;">hello</h1>
|
||||
`,
|
||||
|
||||
ssrHtml: `
|
||||
<h1 class="svelte-szzkfu" style="background-color: red;">hello</h1>
|
||||
<h1 class="svelte-szzkfu" style="background-color: red !important;">hello</h1>
|
||||
`,
|
||||
|
||||
test({ assert, target, window, component }) {
|
||||
const h1s = target.querySelectorAll('h1');
|
||||
|
||||
assert.equal(window.getComputedStyle(h1s[0])['backgroundColor'], 'rgb(0, 0, 255)');
|
||||
assert.equal(window.getComputedStyle(h1s[1])['backgroundColor'], 'rgb(255, 0, 0)');
|
||||
|
||||
component.color = 'yellow';
|
||||
assert.equal(window.getComputedStyle(h1s[0])['backgroundColor'], 'rgb(0, 0, 255)');
|
||||
assert.equal(window.getComputedStyle(h1s[1])['backgroundColor'], 'rgb(255, 255, 0)');
|
||||
}
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
export let color = 'red'
|
||||
</script>
|
||||
|
||||
<h1 style:background-color={color} >hello</h1>
|
||||
<h1 style:background-color|important="{color}">hello</h1>
|
||||
|
||||
<style>
|
||||
h1 {
|
||||
background-color: blue !important;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,15 @@
|
||||
[{
|
||||
"message": "Valid modifiers for style directives are: important",
|
||||
"code": "invalid-style-directive-modifier",
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 8,
|
||||
"character": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 29,
|
||||
"character": 29
|
||||
},
|
||||
"pos": 8
|
||||
}]
|
@ -0,0 +1 @@
|
||||
<button style:color|bad='red'></button>
|
Loading…
Reference in new issue