Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow <slot> as a child of <table> or any of it descendants #6226

Closed
GeorgeTailor opened this issue Dec 14, 2020 · 3 comments
Closed

Allow <slot> as a child of <table> or any of it descendants #6226

GeorgeTailor opened this issue Dec 14, 2020 · 3 comments

Comments

@GeorgeTailor
Copy link

GeorgeTailor commented Dec 14, 2020

Currently HTML <table> supports only basic elements like <thead>, <tbody> and so on along with https://www.w3.org/TR/html52/dom.html#script-supporting-elements-2, which include <script> and <template>.

This is inconvenient since it prevents from using what HTML already has to offer in terms of accessibility and standard tags.

The use case for this would be applying additional styling to each row, as well as nested elements and adding some enhancement with JavaScript.

Not being able to use <slot> in a table forces users to create abominations from <div>'s with a lot of aria-* attributes which, IMO, is unnecessary.
Since slot projects content, the projected content can be evaluated whether or not it should be rendered, for example:

  • User defines <tr slot="row"> as a child of <tbody> - it renders;
  • User defines <option value="invalid">1</option> as a child of <tbody> - it does not render.

Full example:

<script>
	class Table extends HTMLElement {
		constructor() {
			super();
			this.attachShadow({ mode: 'open' }).innerHTML = `
				<table>
					<thead>
						<slot name="header"></slot>
					</thead>
					<tbody>
						<slot name="row"></slot>
					</tbody>
				</table>
			`;
		}
	}
	window.customElements.define('data-table', Table);
</script>
<data-table>
	<tr slot="header">
		<th>header1</th>
	</tr>
	<tr slot="row">
		<td>cell1</td>
	</tr>
	<!-- this should not render -->
	<nav slot="row">
		<td>cell1</td>
	</nav>
</data-table>

</body>

</html>
@GeorgeTailor GeorgeTailor changed the title Allow <slot> as a child of table or any of it descendants Allow <slot> as a child of <table> or any of it descendants Dec 14, 2020
@Yay295
Copy link
Contributor

Yay295 commented Dec 15, 2020

Could you provide an example of what it looks like currently as a comparison?

@GeorgeTailor
Copy link
Author

https://github.com/zooplus/zoo-web-components/blob/master/zoo-modules/grid-modules/grid-module/grid.html

unfortunately, without proper aria-* attributes at the moment.

@annevk
Copy link
Member

annevk commented Dec 15, 2020

This is being discussed in WICG/webcomponents#630 but it's largely a dead end as it requires changes to the HTML parser. I think we best keep the discussion there so I'll close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants