Experimental!
This is a Svelte wrapper component for [email protected]
npm install svelte-a11y-dialog
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>
The
a11y-dialogdocumentation is here
ididStringtrueid attribute added to the dialog element, internally used by a11y-dialog to manipulate the dialog.dialogRootdialogRootString — CSS Selector string.trueclassNamesclassNamesObjectfalse{}base, overlay, document, title, closeButton. See a11y-dialog docs for reference.titletitleStringtrueclasses.title to it.titleIdtitleIdStringfalseid + '-title'.id attribute of the dialog’s title element, used by assistive technologies to provide context and meaning to the dialog window.closeButtonLabelcloseButtonLabelStringfalse'Close this dialog window'aria-label attribute of the close button, used by assistive technologies to provide extra meaning to the usual cross-mark.roleroleStringfalsedialogrole attribute of the dialog element, either dialog (default) or alertdialog to make it a modal (preventing closing on click outside of ESC key).on:instancea11y-dialog instance when a11y-dialog is instantiated via
a Svelte dispatch event. Note that as is idiomatic in dispatched Svelte events, you need to access the instance via event.detail object (see below).a11y-dialog instance once the component has been instantiated. Here's an example of how to set up in your parent component (pay special note of the ev.detail.instance to gain access to the passed a11y-dialog instance!):<script>
const assignDialogInstance = (ev) => {
dialogInstance = ev.detail.instance;
};
const openDialog = () => {
if (dialogInstance) {
dialogInstance.show();
}
};
</script>
<SvelteA11yDialog on:instance={assignDialogInstance} ...etc
titletitlecloseButtonContentcloseButtonLabel\u00D7 (×)closeButtonPositioncloseButtonPositionfirstfirst, last, or noneThis has only been tested client-side.