How to overwrite part of element in custom element inheritance?How to remove shadow root from HTML element adorned with shadow DOM from template? [Web Components]How can I prevent an element from being styled by light DOM styling?Relative paths in custom component libraryHow to add JavaScript to Custom Elements?createElement on Custom Element breaks templateCustom attribute causes custom element styles to be re-injected into headShadow Dom inheriting parent page CSS [Chrome]Vanilla JavaScript event delegation when dealing with Web ComponentsES6 Custom Elements InheritanceOverwrite Shadow Content (User Agent) style in Html5 video element on iOS

How can I improve my violin intonation for enharmonic notes?

Are intrusions within a foreign embassy considered an act of war?

In Street Fighter, what does the M stand for in M Bison?

How do I find which software is doing an SSH connection?

What is this airplane that sits in front of Barringer High School in Newark, NJ?

60's (or earlier) sci-fi short story about two spacecrafts exchanging plants for gold and thinking they got the better of the exchange

What is that ceiling compartment of a Boeing 737?

How much steel armor can you wear and still be able to swim?

Make symbols atomic, without losing their type

Why things float in space, though there is always gravity of our star is present

How did Frodo know where the Bree village was?

How to make all magic-casting innate, but still rare?

What is the maximum that Player 1 can win?

What is the highest power supply a Raspberry pi 3 B can handle without getting damaged?

Is there any possible way to get these hearts as Adult Link?

How are で and いう being used in this context?

How to sort human readable size

What mathematical theory is required for high frequency trading?

Time at 1 g acceleration to travel 100 000 light years

Freewill and rewarding dogs

What could be the physiological mechanism for a biological Geiger counter?

Explicit song lyrics checker

「捨ててしまう」why is there two て’s used here?

"Correct me if I'm wrong"



How to overwrite part of element in custom element inheritance?


How to remove shadow root from HTML element adorned with shadow DOM from template? [Web Components]How can I prevent an element from being styled by light DOM styling?Relative paths in custom component libraryHow to add JavaScript to Custom Elements?createElement on Custom Element breaks templateCustom attribute causes custom element styles to be re-injected into headShadow Dom inheriting parent page CSS [Chrome]Vanilla JavaScript event delegation when dealing with Web ComponentsES6 Custom Elements InheritanceOverwrite Shadow Content (User Agent) style in Html5 video element on iOS






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have parent Custom Element, BasicSwitcher, which has its shadow dom html template:



const template_basic_switcher = document.createElement('template');
template_basic_switcher.innerHTML = `
<style>
@import url("https://use.fontawesome.com/releases/v5.6.3/css/all.css")
</style>

<div id="controls-container">
<span>ON</span>
<span>OFF</span>
</div>
`;


Now I have another Custom Element, ModeSwitcher, inheriting from BasicSwitcher. It has completely different switches.



Is there a way to overwrite just the controls-container part of the template, while still utilizing other part? the element doesn't seem to support any kind of inheritance.










share|improve this question






















  • you can overload the method where you define the template

    – Supersharp
    Mar 25 at 10:13











  • @Supersharp, overload? Did you actually mean "overwrite"? Could you elaborate a bit?

    – Jinghui Niu
    Mar 25 at 11:36

















1















I have parent Custom Element, BasicSwitcher, which has its shadow dom html template:



const template_basic_switcher = document.createElement('template');
template_basic_switcher.innerHTML = `
<style>
@import url("https://use.fontawesome.com/releases/v5.6.3/css/all.css")
</style>

<div id="controls-container">
<span>ON</span>
<span>OFF</span>
</div>
`;


Now I have another Custom Element, ModeSwitcher, inheriting from BasicSwitcher. It has completely different switches.



Is there a way to overwrite just the controls-container part of the template, while still utilizing other part? the element doesn't seem to support any kind of inheritance.










share|improve this question






















  • you can overload the method where you define the template

    – Supersharp
    Mar 25 at 10:13











  • @Supersharp, overload? Did you actually mean "overwrite"? Could you elaborate a bit?

    – Jinghui Niu
    Mar 25 at 11:36













1












1








1








I have parent Custom Element, BasicSwitcher, which has its shadow dom html template:



const template_basic_switcher = document.createElement('template');
template_basic_switcher.innerHTML = `
<style>
@import url("https://use.fontawesome.com/releases/v5.6.3/css/all.css")
</style>

<div id="controls-container">
<span>ON</span>
<span>OFF</span>
</div>
`;


Now I have another Custom Element, ModeSwitcher, inheriting from BasicSwitcher. It has completely different switches.



Is there a way to overwrite just the controls-container part of the template, while still utilizing other part? the element doesn't seem to support any kind of inheritance.










share|improve this question














I have parent Custom Element, BasicSwitcher, which has its shadow dom html template:



const template_basic_switcher = document.createElement('template');
template_basic_switcher.innerHTML = `
<style>
@import url("https://use.fontawesome.com/releases/v5.6.3/css/all.css")
</style>

<div id="controls-container">
<span>ON</span>
<span>OFF</span>
</div>
`;


Now I have another Custom Element, ModeSwitcher, inheriting from BasicSwitcher. It has completely different switches.



Is there a way to overwrite just the controls-container part of the template, while still utilizing other part? the element doesn't seem to support any kind of inheritance.







shadow-dom custom-element html-templates javascript-inheritance






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 6:14









Jinghui NiuJinghui Niu

157211




157211












  • you can overload the method where you define the template

    – Supersharp
    Mar 25 at 10:13











  • @Supersharp, overload? Did you actually mean "overwrite"? Could you elaborate a bit?

    – Jinghui Niu
    Mar 25 at 11:36

















  • you can overload the method where you define the template

    – Supersharp
    Mar 25 at 10:13











  • @Supersharp, overload? Did you actually mean "overwrite"? Could you elaborate a bit?

    – Jinghui Niu
    Mar 25 at 11:36
















you can overload the method where you define the template

– Supersharp
Mar 25 at 10:13





you can overload the method where you define the template

– Supersharp
Mar 25 at 10:13













@Supersharp, overload? Did you actually mean "overwrite"? Could you elaborate a bit?

– Jinghui Niu
Mar 25 at 11:36





@Supersharp, overload? Did you actually mean "overwrite"? Could you elaborate a bit?

– Jinghui Niu
Mar 25 at 11:36












1 Answer
1






active

oldest

votes


















1














1) Create class for you Base Custom Element with a defaut render() method.



class BasicSwitcher extends HTMLElement 
render()
this.shadowRoot.innerHTML = baseTemplate




2) Extend the above class for your inherited Custum Element, and redefine the render() method and use the reference to the new template.



class ModeSwicher extends BasicSwitch () 
render()
this.shadowRoot.innerHTML = otherTemplate




Below is a working snippet:






class BasicSwitcher extends HTMLElement 
constructor()
super()
this.attachShadow( mode: 'open' )
this.render()

render()
this.shadowRoot.innerHTML = BS.innerHTML


customElements.define( 'basic-switch', BasicSwitcher )

class ModeSwitcher extends BasicSwitcher
render()
this.shadowRoot.innerHTML = MS.innerHTML


customElements.define( 'mode-switch', ModeSwitcher )

<template id=BS>
<style> :host display: inline-block ; border: 1px solid gray </style>
<span>Basic Switch</span>
</template>

<template id=MS>
<style> :host display: inline-block ; border: 1px dotted blue ; color: red </style>
<span>Mode Switch</span>
</template>

<basic-switch></basic-switch>

<mode-switch></mode-switch>








share|improve this answer























  • You are a very smart person! IMPRESSIVE!

    – Jinghui Niu
    Mar 25 at 21:51











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332154%2fhow-to-overwrite-part-of-template-element-in-custom-element-inheritance%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














1) Create class for you Base Custom Element with a defaut render() method.



class BasicSwitcher extends HTMLElement 
render()
this.shadowRoot.innerHTML = baseTemplate




2) Extend the above class for your inherited Custum Element, and redefine the render() method and use the reference to the new template.



class ModeSwicher extends BasicSwitch () 
render()
this.shadowRoot.innerHTML = otherTemplate




Below is a working snippet:






class BasicSwitcher extends HTMLElement 
constructor()
super()
this.attachShadow( mode: 'open' )
this.render()

render()
this.shadowRoot.innerHTML = BS.innerHTML


customElements.define( 'basic-switch', BasicSwitcher )

class ModeSwitcher extends BasicSwitcher
render()
this.shadowRoot.innerHTML = MS.innerHTML


customElements.define( 'mode-switch', ModeSwitcher )

<template id=BS>
<style> :host display: inline-block ; border: 1px solid gray </style>
<span>Basic Switch</span>
</template>

<template id=MS>
<style> :host display: inline-block ; border: 1px dotted blue ; color: red </style>
<span>Mode Switch</span>
</template>

<basic-switch></basic-switch>

<mode-switch></mode-switch>








share|improve this answer























  • You are a very smart person! IMPRESSIVE!

    – Jinghui Niu
    Mar 25 at 21:51















1














1) Create class for you Base Custom Element with a defaut render() method.



class BasicSwitcher extends HTMLElement 
render()
this.shadowRoot.innerHTML = baseTemplate




2) Extend the above class for your inherited Custum Element, and redefine the render() method and use the reference to the new template.



class ModeSwicher extends BasicSwitch () 
render()
this.shadowRoot.innerHTML = otherTemplate




Below is a working snippet:






class BasicSwitcher extends HTMLElement 
constructor()
super()
this.attachShadow( mode: 'open' )
this.render()

render()
this.shadowRoot.innerHTML = BS.innerHTML


customElements.define( 'basic-switch', BasicSwitcher )

class ModeSwitcher extends BasicSwitcher
render()
this.shadowRoot.innerHTML = MS.innerHTML


customElements.define( 'mode-switch', ModeSwitcher )

<template id=BS>
<style> :host display: inline-block ; border: 1px solid gray </style>
<span>Basic Switch</span>
</template>

<template id=MS>
<style> :host display: inline-block ; border: 1px dotted blue ; color: red </style>
<span>Mode Switch</span>
</template>

<basic-switch></basic-switch>

<mode-switch></mode-switch>








share|improve this answer























  • You are a very smart person! IMPRESSIVE!

    – Jinghui Niu
    Mar 25 at 21:51













1












1








1







1) Create class for you Base Custom Element with a defaut render() method.



class BasicSwitcher extends HTMLElement 
render()
this.shadowRoot.innerHTML = baseTemplate




2) Extend the above class for your inherited Custum Element, and redefine the render() method and use the reference to the new template.



class ModeSwicher extends BasicSwitch () 
render()
this.shadowRoot.innerHTML = otherTemplate




Below is a working snippet:






class BasicSwitcher extends HTMLElement 
constructor()
super()
this.attachShadow( mode: 'open' )
this.render()

render()
this.shadowRoot.innerHTML = BS.innerHTML


customElements.define( 'basic-switch', BasicSwitcher )

class ModeSwitcher extends BasicSwitcher
render()
this.shadowRoot.innerHTML = MS.innerHTML


customElements.define( 'mode-switch', ModeSwitcher )

<template id=BS>
<style> :host display: inline-block ; border: 1px solid gray </style>
<span>Basic Switch</span>
</template>

<template id=MS>
<style> :host display: inline-block ; border: 1px dotted blue ; color: red </style>
<span>Mode Switch</span>
</template>

<basic-switch></basic-switch>

<mode-switch></mode-switch>








share|improve this answer













1) Create class for you Base Custom Element with a defaut render() method.



class BasicSwitcher extends HTMLElement 
render()
this.shadowRoot.innerHTML = baseTemplate




2) Extend the above class for your inherited Custum Element, and redefine the render() method and use the reference to the new template.



class ModeSwicher extends BasicSwitch () 
render()
this.shadowRoot.innerHTML = otherTemplate




Below is a working snippet:






class BasicSwitcher extends HTMLElement 
constructor()
super()
this.attachShadow( mode: 'open' )
this.render()

render()
this.shadowRoot.innerHTML = BS.innerHTML


customElements.define( 'basic-switch', BasicSwitcher )

class ModeSwitcher extends BasicSwitcher
render()
this.shadowRoot.innerHTML = MS.innerHTML


customElements.define( 'mode-switch', ModeSwitcher )

<template id=BS>
<style> :host display: inline-block ; border: 1px solid gray </style>
<span>Basic Switch</span>
</template>

<template id=MS>
<style> :host display: inline-block ; border: 1px dotted blue ; color: red </style>
<span>Mode Switch</span>
</template>

<basic-switch></basic-switch>

<mode-switch></mode-switch>








class BasicSwitcher extends HTMLElement 
constructor()
super()
this.attachShadow( mode: 'open' )
this.render()

render()
this.shadowRoot.innerHTML = BS.innerHTML


customElements.define( 'basic-switch', BasicSwitcher )

class ModeSwitcher extends BasicSwitcher
render()
this.shadowRoot.innerHTML = MS.innerHTML


customElements.define( 'mode-switch', ModeSwitcher )

<template id=BS>
<style> :host display: inline-block ; border: 1px solid gray </style>
<span>Basic Switch</span>
</template>

<template id=MS>
<style> :host display: inline-block ; border: 1px dotted blue ; color: red </style>
<span>Mode Switch</span>
</template>

<basic-switch></basic-switch>

<mode-switch></mode-switch>





class BasicSwitcher extends HTMLElement 
constructor()
super()
this.attachShadow( mode: 'open' )
this.render()

render()
this.shadowRoot.innerHTML = BS.innerHTML


customElements.define( 'basic-switch', BasicSwitcher )

class ModeSwitcher extends BasicSwitcher
render()
this.shadowRoot.innerHTML = MS.innerHTML


customElements.define( 'mode-switch', ModeSwitcher )

<template id=BS>
<style> :host display: inline-block ; border: 1px solid gray </style>
<span>Basic Switch</span>
</template>

<template id=MS>
<style> :host display: inline-block ; border: 1px dotted blue ; color: red </style>
<span>Mode Switch</span>
</template>

<basic-switch></basic-switch>

<mode-switch></mode-switch>






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 17:10









SupersharpSupersharp

15.9k23879




15.9k23879












  • You are a very smart person! IMPRESSIVE!

    – Jinghui Niu
    Mar 25 at 21:51

















  • You are a very smart person! IMPRESSIVE!

    – Jinghui Niu
    Mar 25 at 21:51
















You are a very smart person! IMPRESSIVE!

– Jinghui Niu
Mar 25 at 21:51





You are a very smart person! IMPRESSIVE!

– Jinghui Niu
Mar 25 at 21:51



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332154%2fhow-to-overwrite-part-of-template-element-in-custom-element-inheritance%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현