native-web-component

Styling default slot in webcomponents

这一生的挚爱 提交于 2020-05-17 07:33:22
问题 In webcomponents, we have two type of slots (named slots and default slots). We can easily style named slots by using syntax slot[name]::slotted(*) . But is there any way that we can style default slots because they don't have any name associated? The code is something like this and i'm using Angular Elements. <div class="topbar-item"> <slot class="icon" name="icon"></slot> <span class="text"> <slot></slot> <-- This is the slot i want to add styles, only if the slot has some data assigned.

Styling default slot in webcomponents

只愿长相守 提交于 2020-05-17 07:31:49
问题 In webcomponents, we have two type of slots (named slots and default slots). We can easily style named slots by using syntax slot[name]::slotted(*) . But is there any way that we can style default slots because they don't have any name associated? The code is something like this and i'm using Angular Elements. <div class="topbar-item"> <slot class="icon" name="icon"></slot> <span class="text"> <slot></slot> <-- This is the slot i want to add styles, only if the slot has some data assigned.

How to use Material Design Icons in a web component?

♀尐吖头ヾ 提交于 2020-05-09 07:01:07
问题 Looks like that mdi is not working inside web components, or do I miss something? I want to develop a web component that encapsulates it's dependencies, adding the link to the parent document works, but it violates the original intent. <html> <body> <x-webcomponent></x-webcomponent> <script> customElements.define( "x-webcomponent", class extends HTMLElement { constructor() { super(); this.attachShadow({ mode: "open" }); this.shadowRoot.innerHTML = ` <style>@import url('https://cdn

Web Components - extend native element's style

纵然是瞬间 提交于 2020-01-25 09:25:09
问题 I would like to extend the native button element but I am not sure how to add styling. In Google's example here they don't use a template so the fancy-button custom element itself is the button, rather than adding a template and shadow DOM containing a button element. It seems to defeat the object of extending a native element if I just add a button directly to the shadow DOM, but I don't know how to style and extend native element. How can I create a custom element which is simply the native

How to have a 'connectedCallback' for when all child custom elements have been connected

做~自己de王妃 提交于 2019-12-29 08:27:10
问题 I'm using Web Components v1. Suppose two Custom Elements: parent-element.html <template id="parent-element"> <child-element></child-element> </template> child-element.html <template id="child-element"> <!-- some markup here --> </template> I'm trying to use connectedCallback in parent-element to initialise the entire parent/child DOM structure when it is attached, which requires interaction with methods defined in child-element . However, it seems child-element isn't properly defined at the

Element.shadowRoot in firefox

笑着哭i 提交于 2019-12-24 20:41:07
问题 How can we workaround Element.shadowRoot in Firefox since it is not available yet ? About Element.shadowRoot https://developer.mozilla.org/en-US/docs/Web/API/Element/shadowRoot 回答1: You need to load the polyfills. But the shadowDOM Polyfill comes with some limitations. Personally I don't use shadowDOM yet unless I know I am going Chrome only. I am waiting for all of the major browsers to support it in their current version and previous version before I start using it all the time. That is

How deal “connectedCallback may be called once your element is no longer connected” coding a Webcomponent

℡╲_俬逩灬. 提交于 2019-12-23 20:12:53
问题 That statement pasted in my question was copied from https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#Using_the_lifecycle_callbacks. As a no-experience developer with Webcomponent, I am trying to understand all rule-of-thumbs and best practices recommended so far. Continuing reading it says "... use Node.isConnected to make sure". It is quite obvious what it means: check if it is still connected but it is not clear, at least for me, what I should do to

CSS: How to target ::slotted siblings in Shadow DOM root?

柔情痞子 提交于 2019-12-22 17:21:14
问题 I know that the spec currently only allows compound selectors for ::slotted, i.e. ::slotted(my-first + my-second) is not allowed, but should something like this be working? ::slotted(x-first) + ::slotted(x-second) { /* css */ } Is there any way to target slotted siblings (other than with global css)? And if not, where would I file such a request? Thanks. 回答1: Sure you can select siblings of slots / slotted . The thing you can not do is select a element which has been slotted and is not a top

can i pass function as attribute to web component?

大城市里の小女人 提交于 2019-12-21 09:33:48
问题 I'm trying to create a native web component for input element. I wanted the component to have custom validation functionality, similar to polymer's paper-input custom validator function. I'm not sure if I can pass a custom validator function as attribute to an instance of (web component) input element. Any suggestions would be appreciated. 回答1: An attribute is a string, not a function. You can pass a a function as a string and then evaluate it with the eval() function. It's not considered as

slot selector limit in web component

人盡茶涼 提交于 2019-12-18 09:07:33
问题 slot is good to make a reusable web component, however, it has a limit so far. What I faced is the style problem. You just can't define the style inside a component, even you know what the inject content's structure would be. Details found from my post in github here I write a component, and try to inject content through slot from the outside and try to add style to the specific content in the component's shadow root. Demo HTML file <my-navbar> <ul> <li>link1</li> <li>link2</li> <li>link3</li