:active bug

by WebComponents

HTML

<style id="COLOR" onload="this.disabled=true">
  div:last-child { /* change to last-of-type and it will always fail */
    color:gold;
  }
</style>
<style>     
  div:last-of-type { background:green }
</style>

<section id="LIST"></section>
<hr>
<button onclick="LIST.innerHTML=''">CLEAR</button>
<button onclick="COLOR.disabled=!COLOR.disabled">Toggle COLOR</button>
<hr>
Objective: Only color the LAST ADDED DIV GREEN
<ol>
<li>Click the ADD button, on Chromium all previous lines remain GREEN (incorrect)</li>
<li>Toggle the GOLD color ON, click the ADD button again, and only the last ADDED line is GREEN (correct)</li>
<li>Take out the ':active' in the shadowRoot STYLE, and only the last line is colored GREEN (correct)</li>
<li>Everything is fine on touch devices</li>
</ol>

<script>
  LIST.attachShadow({mode: 'open'})
      .innerHTML = `<style>:host(:active) button{background:green}</style><slot></slot><button>ADD</button>`;
  LIST.onclick = () => {
  	//setTimeout(()=>{ // adding setTimeout solves the issue
	  	LIST.appendChild(document.createElement('div')).innerHTML="DIV";
    //})
  }
</script>