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

[1.x] Fix inability to click dropdown content in React version #153

Merged
merged 2 commits into from
May 30, 2022

Conversation

jessarcher
Copy link
Member

This PR fixes an issue where the content inside a dropdown (e.g. the "Log Out" link) was unable to be clicked in the React version of Breeze.

The "click away" element (used to trigger the closing of the dropdown when clicking away from it) was covering the dropdown menu, so when you think you are clicking the dropdown, you are actually hitting the click-away element, even though the dropdown has a higher z-index.

This is because the Headless UI Transition component creates a wrapper div by default. The wrapper div has transform and opacity properties which create a new z-index stacking context.

<!-- click away element -->
<div class="fixed inset-0 z-40"></div>

<!-- transition wrapper -->
<div class="transform opacity-100 scale-100">   <-- creates a new stacking context
    <div class="absolute z-50">
        <!-- dropdown content -->
    </div>
</div>

A solution is to tell the Transition component to render as a Fragment which does not render an additional DOM node:

<!-- click away element -->
<div class="fixed inset-0 z-40"></div>

<!-- transition classes are applied directly to the menu -->
<div class="transform opacity-100 scale-100 absolute z-50">
    <!-- dropdown content -->
</div>

This is also how Vue's <transition> component works by default.

I also removed the additional "open" logic because the fragment requires a child node to exist unconditionally, and the show attribute on the <Transition> element already controls the visibility.

The click-away element was covering the content, even though the content
had a higher z-index, because the Transition component wrapped the
content in a `<div>` that started a new stacking context due to the
transform and opacity classes on it.
@taylorotwell taylorotwell merged commit 6f6a258 into 1.x May 30, 2022
@taylorotwell taylorotwell deleted the react-dropdown-fix branch May 30, 2022 13:21
slimani-dev pushed a commit to slimani-dev/breeze that referenced this pull request Jan 21, 2023
…el#153)

* Fix inability to click dropdown content in React version

The click-away element was covering the content, even though the content
had a higher z-index, because the Transition component wrapped the
content in a `<div>` that started a new stacking context due to the
transform and opacity classes on it.

* Linting
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 this pull request may close these issues.

2 participants