{"action":"opened","issue":{"url":"https://api.github.com/repos/w3c/webcomponents/issues/574","repository_url":"https://api.github.com/repos/w3c/webcomponents","labels_url":"https://api.github.com/repos/w3c/webcomponents/issues/574/labels{/name}","comments_url":"https://api.github.com/repos/w3c/webcomponents/issues/574/comments","events_url":"https://api.github.com/repos/w3c/webcomponents/issues/574/events","html_url":"https://github.com/w3c/webcomponents/issues/574","id":178937252,"number":574,"title":"[Shadow] Slotting indirect children","user":{"login":"joelrich","id":4216919,"avatar_url":"https://avatars.githubusercontent.com/u/4216919?v=3","gravatar_id":"","url":"https://api.github.com/users/joelrich","html_url":"https://github.com/joelrich","followers_url":"https://api.github.com/users/joelrich/followers","following_url":"https://api.github.com/users/joelrich/following{/other_user}","gists_url":"https://api.github.com/users/joelrich/gists{/gist_id}","starred_url":"https://api.github.com/users/joelrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joelrich/subscriptions","organizations_url":"https://api.github.com/users/joelrich/orgs","repos_url":"https://api.github.com/users/joelrich/repos","events_url":"https://api.github.com/users/joelrich/events{/privacy}","received_events_url":"https://api.github.com/users/joelrich/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-23T17:58:25Z","updated_at":"2016-09-23T17:58:25Z","closed_at":null,"body":"I am trying to implement a tabs custom element and had to realise that it is probably not possible to implement what I want to do. Let's start with the markup I would like to use:\r\n\r\n```html\r\n<my-tabs>\r\n\t<my-tab>\r\n\t\t<my-tab-title>\r\n\t\t\tTitle 1\r\n\t\t</my-tab-title>\r\n\t\t<my-tab-content>\r\n\t\t\tContent 1\r\n\t\t</my-tab-content>\r\n\t</my-tab>\r\n\t<my-tab>\r\n\t\t<my-tab-title>\r\n\t\t\tTitle 2\r\n\t\t</my-tab-title>\r\n\t\t<my-tab-content>\r\n\t\t\tContent 2\r\n\t\t</my-tab-content>\r\n\t</my-tab>\r\n</my-tabs>\r\n\r\n```\r\n\r\nThe composed DOM should look like this:\r\n\r\n```html\r\n<my-tabs>\r\n\t<ul>\r\n\t\t<li>Title 1</li>\r\n\t\t<li>Title 2</li>\r\n\t</ul>\r\n\t<article>\r\n\t\tContent 1\r\n\t</article>\r\n\t<article hidden>\r\n\t\tContent 2\r\n\t</article>\r\n</my-tabs>\r\n```\r\n\r\n(The titles and contents could still be wrapped with their custom element.)\r\n\r\nMy first attempt was to attach a shadow to my-tabs and use a named slot for the titles and contents:\r\n\r\n```javascript\r\nshadowRoot.innerHTML = `\r\n<slot name=\"title\"><slot>\r\n<slot name=\"content\"><slot>\r\n`;\r\n```\r\n\r\nThe markup would then have been:\r\n\r\n```html\r\n<my-tabs>\r\n\t<my-tab>\r\n\t\t<my-tab-title slot=\"title\">\r\n\t\t\tTitle 1\r\n\t\t</my-tab-title>\r\n\t\t<my-tab-content slot=\"content\">\r\n\t\t\tContent 1\r\n\t\t</my-tab-content>\r\n\t</my-tab>\r\n\t...\r\n</my-tabs>\r\n\r\n```\r\n\r\nThis didn't work because it seems that a slot can only render elements which are a direct child of the shadow holder element. I was already surprised about the fact that I had to set the slot attribute (#343), but I thought that I could still work around this by setting the slot attributes with a MutationObserver if I really wanted to. This, however, seems to be a limitation which cannot be worked around.\r\n\r\nNext, I tried to implement the tabs component without using any slots by coping/cloning the parts I need in a MutationObserver. I quickly had to realise that this solution is simply not good enough because if the titles/contents contain a stateful element, I cannot just copy the HTML/clone the DOM if the user interacts with the stateful element and changes its internal state.\r\n\r\nUnfortunately, it seems like there is not even an imperative API which would allow me to set the slot of an element manually apart from setting the slot attribute. My hope was that assignedSlot might be writeable which would have allowed me to set the slot of the titles/contents without having this direct child limitation. Well, it's readonly.\r\n\r\nDid I miss anything?\r\n\r\nWhat is the reason that you cannot slot an indirect child? Is it performance? If the slot attribute is set and the shadow does not contain a slot with this name, couldn't it just check the next parent until it finds a slot with this name?"}}
{"actor":{"display_login":"joelrich"}}