Closed tkless closed 5 years ago
Did you test it? If yes, then you have your answer. If not, then I guess it doesn't work.
The website says: "It's exactly what we need when it comes to responsive Web Components." Web Components are mostly working with Shadow DOM. So it will be really great if Element Queries working with Shadow DOM.
Shadow DOM isn't used mostly, quite the opposite, since it doesn't have good cross-browser support.
So it will be really great if Element Queries working with Shadow DOM.
I agree, I hope we get it working 👍
Web components are accelerating strong, I did the research, and am building my next platform update on it.
See lit-element, ionic v4, Vaadin, etc
Shadow DOM is ready to be used today.
I'm afraid that's not quite true, but I hope so in the future.
https://caniuse.com/#feat=shadowdomv1
Ionic is using Angular, which is using per default emulated Shadow DOM, where css-element-queries works. Vaadin emulates it as well, as you can see since they support IE 11+, which officially doesn't support Shadow Dom. Never heard of it and lit-element tho'.
However, if you want to contribute, to support native shadow DOM, feel free to create a PR. 👍
Yeah for me element queries wouldbe the most valuable in shadow-doom (web-components). It's bad it's not supported ;(
In our project/framework we use Shadow Dom. We find a solution, that works great for us, as element queries with only few lines of code:
/**
* @summary sets observed responsive breakpoints for an element
* @param {Element} element
* @param {Object} [breakpoints = { SM: 384, MD: 576, LG: 768, XL: 960 }]
*/
function responsive( element, breakpoints = { SM: 384, MD: 576, LG: 768, XL: 960 } ) {
if ( window.ResizeObserver )
new ResizeObserver( updateBreakpoints ).observe( element );
else {
// fallback with MutationObserver if Resize Observer is not supported by the browser
const observer = new MutationObserver( mutations => mutations.forEach( mutation => mutation.type === 'attributes' && mutation.attributeName === 'style' && updateBreakpoints() ) );
observer.observe( element, { attributes: true } );
document.body.querySelectorAll( '*' ).forEach( element => observer.observe( element, { attributes: true } ) );
window.addEventListener( 'resize', updateBreakpoints, false );
updateBreakpoints();
}
function updateBreakpoints() {
for ( const key in breakpoints )
element.classList[ element.offsetWidth >= breakpoints[ key ] ? 'add' : 'remove' ]( key );
}
}
->Hier the link to this code snippet in our project
Try it out :)
Really nice, thank you :). It looks promising and may resolve my issue :). I will just have to properly implement it into my SCSS mixins, probably something like:
@mixin min-hd {
#main-wrapper.XL & { @content; }
}
This does not work: