From c86c1d6e93d978d13e42bbc449e0225a06793ba3 Mon Sep 17 00:00:00 2001 From: Bryce Russell Date: Wed, 24 May 2023 04:48:28 -0500 Subject: [PATCH] Improve outside click detection on search modal (#85) Co-authored-by: Chris Swithinbank --- .changeset/silver-icons-reflect.md | 5 +++++ packages/starlight/components/Search.astro | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/silver-icons-reflect.md diff --git a/.changeset/silver-icons-reflect.md b/.changeset/silver-icons-reflect.md new file mode 100644 index 0000000000..ceb946025d --- /dev/null +++ b/.changeset/silver-icons-reflect.md @@ -0,0 +1,5 @@ +--- +"@astrojs/starlight": patch +--- + +Improve outside click detection on the search modal diff --git a/packages/starlight/components/Search.astro b/packages/starlight/components/Search.astro index a9c0ef739e..6e58b46df7 100644 --- a/packages/starlight/components/Search.astro +++ b/packages/starlight/components/Search.astro @@ -63,7 +63,7 @@ const t = useTranslations(Astro.props.locale); /** Close the modal if a user clicks outside of the modal. */ const onWindowClick = (event: MouseEvent) => { - if (!dialogFrame.contains(event.target as Node)) closeModal(); + if (document.body.contains(event.target as Node) && !dialogFrame.contains(event.target as Node)) closeModal(); }; const openModal = (event?: MouseEvent) => {