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-dialog
documentation is here
id
id
String
true
id
attribute added to the dialog element, internally used by a11y-dialog to manipulate the dialog.dialogRoot
dialogRoot
String
— CSS Selector string.true
classNames
classNames
Object
false
{}
base
, overlay
, document
, title
, closeButton
. See a11y-dialog docs for reference.title
title
String
true
classes.title
to it.titleId
titleId
String
false
id + '-title'
.id
attribute of the dialog’s title element, used by assistive technologies to provide context and meaning to the dialog window.closeButtonLabel
closeButtonLabel
String
false
'Close this dialog window'
aria-label
attribute of the close button, used by assistive technologies to provide extra meaning to the usual cross-mark.role
role
String
false
dialog
role
attribute of the dialog element, either dialog
(default) or alertdialog
to make it a modal (preventing closing on click outside of ESC key).on:instance
a11y-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
title
title
closeButtonContent
closeButtonLabel
\u00D7
(×)closeButtonPosition
closeButtonPosition
first
first
, last
, or none
This has only been tested client-side.