Skip to content

Dropdowns

Dropdown styles for <details> disclosure element content with light-dismiss functionality.

Examples (anchor)

The dropdown styles can be customized before compiling using Sass or in real-time with CSS variables.

Default (anchor)

The dropdowns are standard HTML <details> disclosure elements that are automatically restyled into dropdown components when content within the element is wrapped within one of the three container options shown below.

Default
List type
Body mixed
Example HTML

The name attribute allows only one to be opened at the same time, the .close-dropdown utility enables clicking outside the dropdown to close it and requires the dropdown.js provided with the source files and shared below. Where links are used buttons can also be included if required.

<details name="dropdown-demo">
<summary>Default</summary>
<div class="dropdown">
  <a href="#">Action</a>
  <a href="#">Another action</a>
  <a href="#">Longer action text</a>
</div>
<div class="close-dropdown"></div>
</details>

<details name="dropdown-demo">
<summary>List type</summary>
<ul class="dropdown-list">
  <li><a href="#">Action</a></li>
  <li><a href="#">Another action</a></li>
  <li><a href="#">Longer action text</a></li>
</ul>
<div class="close-dropdown"></div>
</details>

<details name="dropdown-demo">
<summary>Body mixed</summary>
<div class="dropdown-body">
  <h3>With heading</h3>
  <p>The quick brown fox jumps over the lazy dog.</p>
  <button>With button</button>
</div>
<div class="close-dropdown"></div>
</details>

The <summary> element is lightly styled so can be designed to suit the specific conditions in which the dropdowns are being used. The icon styles replicate those from the icons and can be adapted to use the SVG variable tokens if also included.

The .dropdown-btn utility can be used on the <summary> to convert it into a button designed to replicate the forms and buttons content styles and button component utilities.

Default
List type
Body mixed
Example HTML
<details name="dropdown-demo">
<summary class="dropdown-btn">Default</summary>
<div class="dropdown">
  <a href="#">Action</a>
  <a href="#">Another action</a>
  <a href="#">Longer action text</a>
</div>
<div class="close-dropdown"></div>
</details>

<details name="dropdown-demo">
<summary class="dropdown-btn">List type</summary>
<ul class="dropdown-list">
  <li><a href="#">Action</a></li>
  <li><a href="#">Another action</a></li>
  <li><a href="#">Longer action text</a></li>
</ul>
<div class="close-dropdown"></div>
</details>

<details name="dropdown-demo">
<summary class="dropdown-btn">Body mixed</summary>
<div class="dropdown-body">
  <h3>With heading</h3>
  <p>The quick brown fox jumps over the lazy dog.</p>
  <button>With button</button>
</div>
<div class="close-dropdown"></div>
</details>

Fixed light and dark (anchor)

Example HTML
<details name="dropdown-demo">
<summary>Default light</summary>
<div class="dropdown dropdown-light">
  <a href="#">Action</a>
  <a href="#">Another action</a>
  <a href="#">Longer action text</a>
</div>
<div class="close-dropdown"></div>
</details>

<details name="dropdown-demo">
<summary>Default dark</summary>
<div class="dropdown dropdown-dark">
  <a href="#">Action</a>
  <a href="#">Another action</a>
  <a href="#">Longer action text</a>
</div>
<div class="close-dropdown"></div>
</details>
Example HTML
<details name="dropdown-demo" class="dropdown-light">
<summary class="dropdown-btn">Default light</summary>
<div class="dropdown">
  <a href="#">Action</a>
  <a href="#">Another action</a>
  <a href="#">Longer action text</a>
</div>
<div class="close-dropdown"></div>
</details>

<details name="dropdown-demo" class="dropdown-dark">
<summary class="dropdown-btn">Default dark</summary>
<div class="dropdown">
  <a href="#">Action</a>
  <a href="#">Another action</a>
  <a href="#">Longer action text</a>
</div>
<div class="close-dropdown"></div>
</details>

Using the module (anchor)

Load StyleMods as demonstrated (change file path as required) then include the Sass mixin anywhere below.

custom.scss
@use "stylemods/scss" as *;
@include dropdowns-css;

See the using modules page for more information.

Using the framework (anchor)

Using the recommended custom setup enable the styles in an overrides document:

overrides.scss
@use "stylemods/scss/configuration" as *;
$enable-dropdowns: true;

Include the overrides and the framework styles with your custom document for compiling the framework:

custom.scss
@use "overrides";
@use "stylemods/scss/stylemods";

See using the framework for more information.

Source code (anchor)

The Dropdowns source file is included with the components module files, you can view the source code from the latest release (v1.5.0) via the Github link below.

Source documents
stylemods/scss/components/dropdowns.scss
stylemods/js/dropdown.js
View on Github
https://github.com/pmbrown/StyleMods/blob/main/scss/components/dropdowns.scss
https://github.com/pmbrown/StyleMods/blob/main/js/dropdown.js

Shared documentation about how to customize the default property values for the styles using the Sass and CSS variables is provided on the customizing page.