[WICG/webcomponents] HTMLSlotElement.assign() does not work as expected (Issue #954)

It seems like the `HTMLSlotElement.assign()` method is a way for us to programmatically assign an element to a slot, but I can't seem to get it to work as expected.

[Here is a codepen as an example.](https://codepen.io/rpivovar/pen/qBPGYJY?editors=1111)

I've also added some of this code below.

HTML markup:

```html
<some-element><slot>foo</slot></some-element>
```

```js
class SomeElement extends HTMLElement {}

customElements.define('some-element', SomeElement);

const slot = document.querySelector('slot');

const p = document.createElement('p');
p.innerHTML = 'hello';

slot.assign(p); // should this work?
```

I expected `assign()` to set the slot with the given element, but I don't see any change.

Am I misunderstanding how `assign()` should work?

Thanks for the help!

On the other hand, if I do this:

```js
slot.innerHTML = 'hello';
```

This has the desired effect, and it also looks like doing this triggers the `'slotchange'` event.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/954
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/954@github.com>

Received on Thursday, 20 January 2022 01:14:07 UTC