Home

Awesome

Svelte a11y-dialog

Experimental!

This is a Svelte wrapper component for a11y-dialog@7.3.0

Install

npm install svelte-a11y-dialog

Usage

After installing the npm package, import the SvelteA11yDialog component and optionally setup a dialog instance binding:

  import { SvelteA11yDialog } from "svelte-a11y-dialog";
  let dialogInstance;
  const assignDialogInstance = (instance) => {
    dialogInstance = instance;
  }

Then use as follows:

<button
  type="button"
  data-a11y-dialog-show="a11y-dialog"
>Open dialog</button>
<SvelteA11yDialog 
  id="a11y-dialog"
  dialogRoot="#dialog-root"
  closeButtonLabel="My close button label"
  closeButtonPosition="last"
  title="A11yDialog Test"
  titleId="uniqueTitleId"
  role="dialog"
  on:instance={assignDialogInstance}
>
  <svelte:fragment slot="closeButtonContent">
    <span>Close</span>
  </svelte:fragment> 
  <div>
    <p>This is some content</p>
  </div>
</SvelteA11yDialog>

In your main index.html, add a container where your dialog will be rendered into — dialog-root in this example:

<!DOCTYPE html>
<html>
  <body>
    <div id="app"></div>
    <div id="dialog-root"></div>
  </body>
</html>

API

The a11y-dialog documentation is here

id

dialogRoot

classNames

title

titleId

closeButtonLabel

role

Events

on:instance

<script>
  const assignDialogInstance = (ev) => {
    dialogInstance = ev.detail.instance;
  };

  const openDialog = () => {
    if (dialogInstance) {
      dialogInstance.show();
    }
  };
</script>

<SvelteA11yDialog on:instance={assignDialogInstance} ...etc

Slots

title

closeButtonContent

closeButtonPosition

Server-side Rendering

This has only been tested client-side.