DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (f47094b3b694)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<!DOCTYPE html>
<html>
<head>
<title>Shadow DOM: slotchange customelements</title>
<meta name="author" title="Surma" href="mailto:surma@google.com">
<link rel="help" href="https://dom.spec.whatwg.org/#signaling-slot-change">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<slots-in-constructor id="constructor-upgrade"><div></div></slots-in-constructor>
<slots-in-callback id="callback-upgrade"><div></div></slots-in-callback>
<script>
var calls = [];
class SlotsInConstructor extends HTMLElement {
    constructor() {
        super();
        this.attachShadow({mode: 'open'});
        this.shadowRoot.innerHTML = '<slot></slot>';
        var slot = this.shadowRoot.children[0];
        slot.addEventListener('slotchange', function() {
            calls.push(this.id);
        }.bind(this));
    }
}
customElements.define('slots-in-constructor', SlotsInConstructor);
class SlotsInCallback extends HTMLElement {
    constructor() {
        super();
    }

    connectedCallback() {
        this.attachShadow({mode: 'open'});
        this.shadowRoot.innerHTML = '<slot></slot>';
        var slot = this.shadowRoot.children[0];
        slot.addEventListener('slotchange', function() {
            calls.push(this.id);
        }.bind(this));
    }
}
customElements.define('slots-in-callback', SlotsInCallback);
</script>
<slots-in-constructor id="constructor-parser"><div></div></slots-in-constructor>
<slots-in-callback id="callback-parser"><div></div></slots-in-callback>
<script>
test(function () {
    assert_true(calls.includes("constructor-parser"));
    assert_true(calls.includes("callback-parser"));
    assert_true(calls.includes("constructor-upgrade"));
    assert_true(calls.includes("callback-upgrade"));
}, 'slotchange must fire on initialization of custom elements with slotted children');
done();
</script>
</body>
</html>