Skip to content

Usage

<script src="/src/js/modal-init.js"></script>

<dialog class="modal">
  <form method="dialog">
    <button class="button theme">Close</button>
  </form>

  <div class="content">
    <div class="l-stack">
      <h2>Some Content</h2>
      <p>Some text</p>
      <a href="/">Call to action</a>
    </div>
  </div>
</dialog>

<button class="button theme showModal" style="margin-inline: auto;">Open Modal</button>

Document the approaches available of preventing scrolling when the modal is open. How to prevent layout shift when scrollbar disappears (more evident when the background content is visible)

This implimentation of the modal component uses the dialog element.

You can set the color of the background behind the modal using the ::backdrop psuedo-selector. However, it does not currently inherit custom properties.

User scroll should be prevented when the modal is open. This implimentation uses the body-scroll-lock package, which handles scroll locking for a variety of browsers and device types.

This implimentation provides focus trapping to keep the tabbing context within the modal.

  • document the styles that are included (ex. positioning)