Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot close menu/dropdown by clicking iframe #707

Closed
horans opened this issue Jul 30, 2021 · 2 comments · Fixed by #1552
Closed

[Bug]: Cannot close menu/dropdown by clicking iframe #707

horans opened this issue Jul 30, 2021 · 2 comments · Fixed by #1552

Comments

@horans
Copy link

horans commented Jul 30, 2021

What package within Headless UI are you using?

@headlessui/vue

What version of that package are you using?

v1.4.0

What browser are you using?

Chrome v92

Reproduction repository

https://headlessui.dev/vue/menu

Describe your issue

When a menu/dropdown is open, it cannot be closed by interacting(click) with iframe on the page.

Reproduction:

  1. Click left top react/vue menu to open
  2. Click right preview area (which is a iframe)

Expecting: close/blur menu
Result: menu stay as open/focus

Reference: https://gist.github.com/jaydson/1780598

@biesbjerg
Copy link

biesbjerg commented Mar 11, 2022

Maybe this can help someone, until a proper fix is implemented:

<template>
  <Listbox>
    <ListboxOptions ref="optionsRef">...</ListboxOptions>
  </Listbox>
</template>

<script lang="ts">
export default defineComponent({
  setup() {
    const optionsRef = ref<typeof ListboxOptions>();

    const closeOnIframeClick = async () => {
      const activeElement = document.activeElement as HTMLElement | null;
      if (activeElement instanceof HTMLIFrameElement) {
        optionsRef.value?.el?.dispatchEvent(
          new KeyboardEvent("keydown", {
            key: "Escape"
          })
        );

        await nextTick();

        const ownerActiveElement = activeElement.ownerDocument.activeElement as HTMLElement | null;
        if (ownerActiveElement) {
          ownerActiveElement.blur?.();
        }
      }
    };

    onMounted(() => {
      window.addEventListener("blur", closeOnIframeClick);
    });

    onUnmounted(() => {
      window.removeEventListener("blur", closeOnIframeClick);
    });

    return {
      optionsRef
    };
  }
});
</script>

@thecrypticace
Copy link
Contributor

thecrypticace commented Jun 3, 2022

Hey! Thank you for your bug report!
Much appreciated! 🙏

This should be fixed by #1552, and will be available in the next release.

You can already try it using npm install @headlessui/vue@insiders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants