shadow-dom

JavaScript within Shadow DOM best practices

心已入冬 提交于 2019-12-04 05:43:53
I'm having trouble getting JavaScript to run properly within Shadow DOM elements I'm defining. Given the following code: <template id='testTemplate'> <div id='test'>Click to say hi</div> <script> var elem = document.querySelector('#test'); elem.addEventListener('click', function(e) { alert("Hi there"); }); </script> </template> <div id="testElement">Host text</div> <script> var shadow = document.querySelector('#testElement').createShadowRoot(); var template = document.querySelector('#testTemplate'); shadow.appendChild(template.content.cloneNode(true)); </script> document.querySelector is

Adding CodeMirror to Shadow Dom of Custom Element?

纵饮孤独 提交于 2019-12-04 05:16:21
问题 I'd like to dynamically create a CodeMirror instance inside a Custom Element and have it live inside the element's Shadow DOM. For example: <code-mirror>foo</code-mirror> <script> window.customElements.define('code-mirror', class extends HTMLElement { constructor() { super(); let shadowRoot = this.attachShadow({mode: 'open'}); } connectedCallback() { this.cm = CodeMirror(this.shadowRoot, {lineNumbers: true}); } }); </script> This "works" but the layout is all wrong.. margin-left gets set to

What are the drawbacks of using Shadow DOM?

為{幸葍}努か 提交于 2019-12-04 04:10:13
问题 In the tutorials I see only the benefits of Shadow DOM, but there should be drawbacks as well. In which cases should we avoid using Shadow DOM? 回答1: Shadow DOM features can be seen as drawback as much as benefits: Style isolation is a benefit if you want it but a drawback if a user wants to style a component with Shadow DOM from a global CSS stylesheet. DOM Shadowing is a benefit in some cases, but a drawback if an external script/library or extension needs to parse or select the content.

Inspect shadow dom with Firefox

╄→尐↘猪︶ㄣ 提交于 2019-12-04 00:00:28
Is there a way to inspect shadow dom elements in Firefox like you can do with the Chrome dev tools? Mike Ratcliffe Yes, we have added shadow DOM inspection to Firefox 65.0+ DevTools. Shadow DOM in normal content pages is always displayed e.g. By default shadow DOM for built in browser features is not displayed e.g here is a video element: To enable viewing of the Shadow DOM for built in features: Go to about:config Set devtools.inspector.showUserAgentShadowRoots to true After changing this setting you need to restart DevTools (or restart Firefox). Now the Shadow DOM for built-in elements will

Element transclusion

岁酱吖の 提交于 2019-12-03 20:31:12
Is there something like angularjs directive's transclude attribute in polymer? Something what allows me to include some elements to a specific place in template? I would like to achieve something like following: <my-header title="My title"> <my-header-item name="Item 1"></my-header-item> <my-header-item name="Item 2"></my-header-item> </my-header> which might be expressed: <h1>My title</h1> <!-- "My title" given by my-header's title attribute --> <ul> <li>Item 1 <!-- given by my-header-item --> <li>Item 2 </ul> I am not sure if this is a task for polymer or if this is a typical way to use

Does anybody know how to identify shadow dom web elements using selenium webdriver?

若如初见. 提交于 2019-12-03 20:30:50
We are using selenium web driver and python for our test automation and trying to automate html5 app with shadow dom design. Unable to identify any elements that come under shadow-root. For eg. If I want to access any element under the shadow root given below then how can I do that? Any help is appreciated. You can inject this piece of javascript that does this and then run the find_element methods on that element: shadow_section = mydriver.execute_script('''return document.querySelector("neon-animatable").shadowRoot''') shadow_section.find_element_by_css(".flex") since you use often that you

ContentEditable in Shadow DOM?

北城以北 提交于 2019-12-03 16:11:22
I'm trying to create a Polymer element for contenteditable. I create a contenteditable div, place this.innerHTML there, and it becomes editable. All good with polyfills, e.g. in Firefox. But it doesn't work in Chrome 35 with native Shadow DOM. Well, it is still editable, but neither document.execCommand nor window.getSelection is working. document.execCommand does nothing. window.getSelection().getRangeAt(0).toString() is defined but empty. No error is shown. So I cannot style the selection. Does anybody know whether it's possible to make a custom editable element or not? What am I doing wrong

Light DOM style leaking into Shadow DOM

自闭症网瘾萝莉.ら 提交于 2019-12-03 16:06:07
I am trying to create a Chrome extension with a floating widget. To do that, I have to isolate my element from the rest of the page. Shadow DOM looks like a perfect fit for that, but it isn't doing what I expected. Here is my content script: content.js var lightDom = document.createElement('style'); lightDom.innerText = 'div { color: red }'; document.body.appendChild(lightDom); var shadowDom = document.createElement('div'); document.body.appendChild(shadowDom); var shadowRoot = shadowDom.attachShadow({'mode': 'open'}); shadowRoot.innerHTML = ` <style> div { background-color: blue; } </style>

How to distribute (insert) content nodes programmatically

99封情书 提交于 2019-12-03 15:19:51
问题 Is there a way to programmatically distribute (insert) content from lightDOM to ShadowDOM? I would like to wrap every single child node into an element. For example : <my-list> <span>first element</span> <div>second element</div> <a>third element</a> </my-link> to be distributed as <my-list> <ul> <li> <span>first element</span> </li> <li> <div>second element</div> </li> <li> <a>third element</a> </li> </ul> </my-link> I need it not only to render that way, but also delegate entire HTML

Does IOS Safari support Shadow DOM?

落爺英雄遲暮 提交于 2019-12-03 13:48:37
My application is able to render the Shadow DOM, but the inspector cannot display the shadow root. Can anyone help me out on this? It depends on which Shadow DOM you mean—Shadow DOM v0 or Shadow DOM v1. See http://caniuse.com/#feat=shadowdomv1 and http://caniuse.com/#feat=shadowdom No version of Safari supports Shadow DOM v0. But as far as iOS Safari, version 10.2+ support Shadow DOM v1 with the following limitation: Certain CSS selectors do not work ( :host > .local-child ) and styling slotted content ( ::slotted ) is buggy. As far as differences between Shadow DOM v0 and v1, see https:/