Add Responsive-Friendly Enhancements to <details> with <details-utils>

Zach created a very handy Web Component that augments and wraps around a <details> element. He’s named it <details-utils>.

This web component adds five new responsive-friendly enhancements to one or more <details> elements nestled inside:

  • Force open/closed
  • Click outside to close
  • Close on esc
  • Animate open/closed
  • Toggle root element class

Using attributes you can control the behavior. Additionally, you can pass in media queries into (most of) the attribute values to make them respond to viewport sizes. For example, to have a <details> be automatically opened below a certain viewport size, you can use this:

<details-utils force-open="(max-width: 767px)">
	<details>
		<summary>Force open at small viewport</summary>
		<div class="demo-content">
			<p>This is the content.</p>
		</div>
	</details>
</details-utils>

Handy!

Introductory Blogpost →
Demo →
Source (GitHub) →

Published by Bramus!

Bramus is a frontend web developer from Belgium. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.