custom-element

webcomponents - hide dropdown menu on window.onclick

本小妞迷上赌 提交于 2019-12-31 05:31:15
问题 dropdown menu is created in shadowDOM almost perfect, but the problem is how to hide the dropdown menu when click on any where else in window class NavComponent extends HTMLElement { constructor() { super(); let template = document.currentScript.ownerDocument.querySelector('template'); let clone = document.importNode(template.content, true); let root = this.attachShadow({ mode: 'open' }); root.appendChild(clone); } connectedCallback() { let ddc = this.shadowRoot.querySelectorAll('

How can I create a web component that acts like a form element?

ε祈祈猫儿з 提交于 2019-12-29 01:34:26
问题 I am trying to create a web component that is usable in a form element specifically, that has a name , and a value . I recognize that I can create a web component that extends an HTMLInputElement : <input is="very-extended"> but I am trying to create an entirely new element. When creating a regular web component, you can create it from the prototype of a regular HTMLElement ( HTMLElement.prototype ). Which leads me to assume that I can create a different element with the prototype of an

Use of Template with HTML Custom Elements

↘锁芯ラ 提交于 2019-12-28 03:10:20
问题 I just started learning about the HTML custom elements, and through reading a series of intros, tutorials, and documentation, I think I have a good handle on how it works, but I have a philosophical question on the proper way to use or not use the <template> tag. Custom elements give you the ability to encapsulate new functionality, simplifying the structure of your HTML document, and allowing you to simply insert a <my-custom-element>...</my-custom-element> tag instead of <div class="my

External Styling for CustomElements V1 & ShadowDOM

怎甘沉沦 提交于 2019-12-25 09:08:23
问题 Whilst this may seem to be a duplicate question those asked previously have been based around Polymer, not native CustomElements, and this is about the css itself, not penetrating the ShadowDOM or Custom CSS Properties / Variables So here we have a simple Custom Element (note: as of writing this only works in newer Chrome versions) class StyleMe extends HTMLElement { constructor () { super(); let shadow = this.attachShadow({ mode: 'closed' }); shadow.appendChild(document.querySelector('#style

Aurelia 2 custom elements (already sharing a view via @) doing almost the same thing, how to refactor?

时光毁灭记忆、已成空白 提交于 2019-12-25 04:37:22
问题 Here is my problem: Aurelia app: a few custom elements (already sharing a view via @UseView) doing almost the same thing (specific func shoud be defined by every element itself), how to manage shared code (inkl @bindable)? How to refactor this: https://gist.run/?id=897298ab1dad92fadca77f64653cf32c 回答1: The "shared" code you refer to in your question is lifecycle-related stuff in your custom elements, which isn't really suited for sharing. You would need to do inheritance, and with custom

Creating new element with a dynamic extends class expression

不打扰是莪最后的温柔 提交于 2019-12-24 13:52:45
问题 Is it possible to pass a class expression as parameter? Have not tried the eval route yet.. // CardtsElements.Zone contains a valid class expression // used to create a valid Zone Custom Element let extend = (source, name, definitionClassExpression) => customElements.define('CARDTS-' + name, class extends CardtsElements[source] definitionClassExpression); ^^^^SYNTAX ERROR^^^^^^^^^^ // Create a new 'CARDTS-FOUNDATION' element extending 'CARDTS-ZONE' extend('Zone','Foundation', { static get

Images created using `document.currentScript.ownerDocument.createElement` (from within <link> imported HTML) never load

女生的网名这么多〃 提交于 2019-12-24 12:05:21
问题 Here's a function that returns the width of an image, given the image's url: async function getImageWidthByUrl(imgUrl) { const imgEl = document.createElement("img"); let untilImgLoaded = new Promise((resolve, reject) => { imgEl.onload = resolve; imgEl.onerror = reject; }); imgEl.src = imgUrl; await untilImgLoaded; return imgEl.naturalWidth; } It works fine. It also (of course) works if we use new Image() instead of document.createElement("img") . However, the document.createElement("img")

Custom HTML elements

試著忘記壹切 提交于 2019-12-24 09:13:01
问题 The HTML spec describes several kinds of elements stored in the CustomElementRegistry . Builtin elements like <a> that are represented by a builtin subclass of HTMLElement like HTMLAnchorElement . Autonomous custom elements like <my-element> which extend HTMLElement and register with the CustomElementRegistry . Customized builtin elements like <a is="my-link"> which extend a subclass of HTMLElement and use the is="customized-tag-name" to specify the class. Legacy elements like <isindex> which

Angular - Custom Elements not working on Firefox & Microsoft Edge & Internet Explorer

时光总嘲笑我的痴心妄想 提交于 2019-12-24 07:41:07
问题 I tried this Angular Elements Demo I downloaded, installed, and built that demo on local. Then, used the following code: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Angular Elements Demo</title> </head> <body> <hello-world name="Anna"></hello-world> <script src="dist/main.js"></script> <script> const helloCp = document.querySelector('hello-world'); helloCp.addEventListener('hi', (data) => { console.log(data.detail); }); setTimeout(() => { helloCp.setAttribute('name',

Global CSS for an app with web components

旧巷老猫 提交于 2019-12-24 00:15:00
问题 I'm developing a web application that uses HTML 5 native web components. My problem is that I have a lot of common CSS for all of these and I use font awesome to have nice icons. Right now I put all my styles inside "/deep" shadow piercing but Chrome says : "/deep/ combinator is deprecated." Do you have any suggestions on how can I have global CSS and CSS libraries (like font awesome) available on the whole app ? Thanks :) 回答1: You could include the CSS font file globally, with the <link rel=