-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(slotted): fix applying polyfilled slotted css to nested slot
Closes #2183
- Loading branch information
1 parent
e9c36fd
commit e4229db
Showing
7 changed files
with
172 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
:host { | ||
display: inline-flex; | ||
border: 2px dashed gray; | ||
padding: 2px; | ||
} | ||
|
||
/* 1. [Edge] no border on default slot */ | ||
.content ::slotted(*) { | ||
background-color: rgb(0, 255, 0); | ||
} | ||
|
||
/* 2. [Edge] extra border shows up on host */ | ||
::slotted(:not([slot="header-slot-name"])) { | ||
border: 4px solid rgb(0, 0, 255); | ||
color: rgb(0, 0, 255); | ||
font-weight: bold; | ||
} | ||
|
||
::slotted([slot="header-slot-name"]) { | ||
border: 4px solid rgb(255, 0, 0); | ||
color: rgb(255, 0, 0); | ||
font-weight: bold; | ||
} | ||
|
||
::slotted(*) { | ||
margin: 8px; | ||
padding: 8px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Component, h, Host } from '@stencil/core'; | ||
|
||
|
||
@Component({ | ||
tag: 'slotted-css', | ||
styleUrl: 'cmp.css', | ||
shadow: true, | ||
}) | ||
export class SlottedCss { | ||
render() { | ||
return ( | ||
<Host> | ||
<section> | ||
<header> | ||
<slot name="header-slot-name" /> | ||
</header> | ||
<section class="content"> | ||
<slot /> | ||
</section> | ||
<footer> | ||
<slot name="footer-slot-name" /> | ||
</footer> | ||
</section> | ||
</Host> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf8"> | ||
<script src="/build/testapp.esm.js" type="module"></script> | ||
<script src="/build/testapp.js" nomodule></script> | ||
|
||
<slotted-css> | ||
<div class="red" slot="header-slot-name">header-slot-name: red color and border</div> | ||
<div class="green">default slot: green background, blue border and color</div> | ||
<div class="blue" slot="footer-slot-name">footer-slot-name: blue color and border</div> | ||
</slotted-css> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { setupDomTests } from '../util'; | ||
|
||
|
||
describe('slotted css', function() { | ||
const { setupDom, tearDownDom } = setupDomTests(document); | ||
let app: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
app = await setupDom('/slotted-css/index.html'); | ||
}); | ||
afterEach(tearDownDom); | ||
|
||
|
||
it('assign slotted css', async () => { | ||
const elm = app.querySelector('slotted-css'); | ||
|
||
const redElm = elm.querySelector('.red'); | ||
const redStyles = window.getComputedStyle(redElm); | ||
expect(redStyles.color).toEqual('rgb(255, 0, 0)'); | ||
|
||
// green background, blue border and color | ||
const greenElm = elm.querySelector('.green'); | ||
const greenStyles = window.getComputedStyle(greenElm); | ||
expect(greenStyles.backgroundColor).toEqual('rgb(0, 255, 0)'); | ||
expect(greenStyles.color).toEqual('rgb(0, 0, 255)'); | ||
|
||
const blueElm = elm.querySelector('.blue'); | ||
const blueStyles = window.getComputedStyle(blueElm); | ||
expect(blueStyles.color).toEqual('rgb(0, 0, 255)'); | ||
|
||
}); | ||
|
||
}); |