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) => {