When you click on anchor element like this document set a target element internally, activating
:target
pseudo selector.
This does not happen when your :target
element is inside a shadowRoot link to bug.
It turns out that is not a bug and they are following the spec.
In my opinion this is a limitation and ultimately css should work everywhere independently where are used.
At least we should allow shadowRoot to define a target element like document does.
let template = `
location-1
title-1
`;
customElements.define('my-component', class myElement extends HTMLElement {
constructor() {
super();
let shadowRoot = this.attachShadow({ mode: 'open' });
shadowRoot.innerHTML = template;
window.addEventListener('popstate', function () {
shadowRoot.targetElement = document.targetElement;
});
}
});