From 70be140197d2e65d4010673196443942c203126d Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 17 Sep 2026 16:11:31 -0700 Subject: [PATCH] Human edit round of dialog JS docs, refs #2790 --- docs/javascript_plugins.rst | 65 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/docs/javascript_plugins.rst b/docs/javascript_plugins.rst index ba949c12..4dd3f809 100644 --- a/docs/javascript_plugins.rst +++ b/docs/javascript_plugins.rst @@ -1,7 +1,7 @@ .. _javascript_plugins: -JavaScript plugins -================== +JavaScript in plugins +===================== Datasette can run custom JavaScript in several different ways: @@ -35,7 +35,7 @@ Your JavaScript code can listen out for this event using ``document.addEventList datasetteManager ---------------- -The ``datasetteManager`` object +The ``datasetteManager`` object ``VERSION`` - string The version of Datasette @@ -481,14 +481,12 @@ Reusable modal dialogs Plugins can use ``DatasetteModal`` to create dialogs with the same appearance and keyboard behavior as Datasette's built-in dialogs. The component provides a native modal dialog, shared styles, Escape and backdrop dismissal, busy-state dismissal guards and focus restoration. -Use the :ref:`javascript_datasette_init` event to set up a dialog, as in this example. - Creating a dialog ~~~~~~~~~~~~~~~~~ ``DatasetteModal.create()`` returns a detached ```` element containing a native ````. Access that native element through ``modal.dialog``. Populate its content before appending the wrapper to the page, then call ``modal.show()`` to open it. -This example adds a button that opens a reusable dialog: +This example uses the :ref:`datasette_init event ` to add a button that opens a dialog: .. code-block:: javascript @@ -504,6 +502,7 @@ This example adds a button that opens a reusable 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 = `