+
Export these rows from the plants table as CSV:
+
+ - Monstera deliciosa
+ - Ficus lyrata
+ - Pilea peperomioides
+
+
+ `;
+
+ const [cancelButton, exportButton] = dialog.querySelectorAll(".modal-footer button");
+ cancelButton.addEventListener("click", () => modal.requestClose("cancel"));
+ exportButton.addEventListener("click", () => modal.close());
+ openButton.addEventListener("click", () => {
+ modal.show({ returnFocusTo: openButton, initialFocus: exportButton });
+ });
+
+ document.body.append(modal);
+ document.querySelector("section.content").append(openButton);
+});
diff --git a/docs/shots/modal-example.js b/docs/shots/modal-example.js
new file mode 100644
index 00000000..fd8210ab
--- /dev/null
+++ b/docs/shots/modal-example.js
@@ -0,0 +1,38 @@
+document.addEventListener("datasette_init", () => {
+ const openButton = document.createElement("button");
+ openButton.type = "button";
+ openButton.textContent = "Open example dialog";
+ // Indicate that this button opens a dialog:
+ openButton.setAttribute("aria-haspopup", "dialog");
+ // Identify which dialog it controls:
+ openButton.setAttribute("aria-controls", "my-plugin-dialog");
+
+ const modal = DatasetteModal.create();
+ const dialog = modal.dialog;
+ dialog.id = "my-plugin-dialog";
+ // Tell screenreaders the dialog is labelled by #my-plugin-dialog-title
+ dialog.setAttribute("aria-labelledby", "my-plugin-dialog-title");
+ dialog.innerHTML = `
+
+
+ This dialog uses Datasette's shared styles and keyboard behavior.
+
+ `;
+
+ const closeButton = dialog.querySelector("button");
+ closeButton.addEventListener("click", () => {
+ modal.requestClose("cancel");
+ });
+ openButton.addEventListener("click", () => {
+ modal.show({ returnFocusTo: openButton, initialFocus: closeButton });
+ });
+
+ document.body.append(modal);
+ document.querySelector("section.content").append(openButton);
+});
diff --git a/pyproject.toml b/pyproject.toml
index edabae2d..cd8b5513 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -87,6 +87,9 @@ dev = [
playwright = [
"pytest-playwright>=0.8.0",
]
+shots = [
+ "shot-scraper>=1.12",
+]
[project.optional-dependencies]
rich = ["rich"]