-
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dialogs): backward compatible dialog usage (#2816)
- Loading branch information
Showing
2 changed files
with
20 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//@ts-ignore | ||
import dialogPolyfill from "https://cdn.jsdelivr.net/npm/[email protected]/dist/dialog-polyfill.esm.min.js" | ||
|
||
import { useEventListener } from "../common/useEventListener.js" | ||
import { html, useLayoutEffect, useRef } from "../imports/Preact.js" | ||
|
||
|
@@ -80,10 +83,16 @@ export const ExportBanner = ({ notebook_id, print_title, open, onClose, notebook | |
const element_ref = useRef(/** @type {HTMLDialogElement?} */ (null)) | ||
|
||
useLayoutEffect(() => { | ||
if (element_ref.current != null && typeof HTMLDialogElement !== "function") dialogPolyfill.registerDialog(element_ref.current) | ||
}, [element_ref.current]) | ||
|
||
useLayoutEffect(() => { | ||
// Closing doesn't play well if the browser is old and the dialog not open | ||
// https://github.com/GoogleChrome/dialog-polyfill/issues/149 | ||
if (open) { | ||
element_ref.current?.show() | ||
element_ref.current?.open === false && element_ref.current?.show?.() | ||
} else { | ||
element_ref.current?.close() | ||
element_ref.current?.open && element_ref.current?.close?.() | ||
} | ||
}, [open, element_ref.current]) | ||
|
||
|
@@ -97,7 +106,7 @@ export const ExportBanner = ({ notebook_id, print_title, open, onClose, notebook | |
) | ||
|
||
return html` | ||
<dialog id="export" inert=${!open} ref=${element_ref}> | ||
<dialog id="export" inert=${!open} open=${open} ref=${element_ref}> | ||
<div id="container"> | ||
<div class="export_title">export</div> | ||
<!-- no "download" attribute here: we want the jl contents to be shown in a new tab --> | ||
|