diff --git a/CHANGELOG.md b/CHANGELOG.md index c71095307..02fcd3518 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ - Keyboard users can now Tab to a dismissible alert’s Close button and press Enter or Space to dismiss it. ([#1612](https://github.com/sqlpage/SQLPage/issues/1612)) - The search field of the `shell` now uses `search_placeholder` as its accessible name, so screen readers announce the customized text instead of the fixed English "Search". ([#1628](https://github.com/sqlpage/SQLPage/issues/1628)) +- Modals can set a header `color`, and `visible` opens that dialog once when the page loads. The page address stays unchanged, and closing it does not open it again when later content loads. + ## v0.48.0 (2026-11-12) - Updated Rust and browser dependencies, including ApexCharts 8.8.1, Tabler 1.7.4, Tabler icons 3.51, and Tom Select 2.7. Chart series names and labels now display HTML as text, fixing upstream script injection in legends and tooltips. diff --git a/examples/official-site/reference/components/modal/05-colored-header.sql b/examples/official-site/reference/components/modal/05-colored-header.sql new file mode 100644 index 000000000..639a7a7d0 --- /dev/null +++ b/examples/official-site/reference/components/modal/05-colored-header.sql @@ -0,0 +1,20 @@ +/* +A modal with a colored header + +A modal with a colored header, opened by a button. The header uses the color and a contrasting foreground; the body stays in the normal text color. +*/ +select + 'modal' as "component", + 'colored_modal' as "id", + 'Saved' as "title", + 'green' as "color", + 'Close' as "close"; + +select + 'The header uses the chosen color.' as "contents_md"; + +select 'button' as "component"; + +select + 'Open a colored modal' as "title", + '#colored_modal' as "link"; diff --git a/frontend/src/sqlpage.ts b/frontend/src/sqlpage.ts index e616f050b..c05c82036 100644 --- a/frontend/src/sqlpage.ts +++ b/frontend/src/sqlpage.ts @@ -533,12 +533,38 @@ function sqlpage_modal(root: InitRoot) { // .page instead of the viewport. The modal then scrolls with the page // content and ends up behind its own backdrop, so its buttons cannot be // clicked. Moving modals to
keeps them viewport-fixed. - for (const modal of select_all(root, "body .page .modal", HTMLElement)) { - document.body.appendChild(modal); - // The modal leaves the original root; announce its subtree separately so - // every initializer, including later-loaded bundles, can still see it. + const modals = select_all(root, "body .page .modal", HTMLElement); + for (const modal of modals) document.body.appendChild(modal); + // The modals left the original root; announce each subtree separately so + // every initializer, including later-loaded bundles, can still see it. The + // event runs this function again, so move them all first: a dialog opened + // below must not be moved afterwards. + for (const modal of modals) { modal.dispatchEvent(new CustomEvent("fragment-loaded", { bubbles: true })); } + + // `visible` opens the last such dialog once. A hash that already names a + // different modal keeps that dialog. Clearing every marker stops a later + // pass from opening an earlier dialog or reopening one the user closed. + const visible_modals = document.querySelectorAll