-
Notifications
You must be signed in to change notification settings - Fork 45
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
Background page scrolls to top when clicking on select listbox in modal #963
Comments
@idealerror Converting your code to a Volt component (below), I cannot reproduce your issue. It may be something in the underlying page, shown in your video, that's causing the 'jump'. If you can provide a copy/pasteable example (preferably in a Volt component) that consistently reproduces the issue, that will help. Volt component:
|
@idealerror CORRECTION: I can now reproduce your issue. (Might have been caching on my end) |
@idealerror For me, the issue does not occur the first time I visit the page (e.g. when the
@joshhanley Any insights? |
@idealerror thanks for reporting and thanks @jeffchown for the component! Yeah this one looks deep, going to have to dig into it properly later. I found a simpler way:
|
Interesting that the simpler way causes the same issue - I thought selecting an option from the select might be triggering it. Guess not. Thanks, @joshhanley |
Alright, I got to the bottom of it and have submitted a PR with a fix! As a consequence, the fix also fixes #764 😁 PR description below. The scenarioIf you have a modal/ slideover that contains a non-native select, then opening, closing, and then re-opening the select dropdown causes the page to scroll back to the top. <?php
use Livewire\Volt\Component;
new class extends Component {
//
}; ?>
<div>
<div class="h-screen">Scroll down...</div>
<div class="h-screen">Scroll down...</div>
<flux:modal.trigger name="edit-profile">
<flux:button x-on:click="console.log('open')" variant="primary">Edit profile</flux:button>
</flux:modal.trigger>
<flux:modal name="edit-profile" variant="flyout">
<flux:select variant="listbox" searchable class="mt-6">
<flux:option value="all">All Changes</flux:option>
<flux:option value="active">Active Items</flux:option>
<flux:option value="created">Added Items</flux:option>
<flux:option value="deleted1">Deleted Items</flux:option>
<flux:option value="deleted2">Deleted Items</flux:option>
</flux:select>
</flux:modal>
</div> The problemIt took a while to find exactly what the problem was, but ultimately the problem is that the dropdown anchorable is trying to reposition when the dropdown is reopened. Digging through the code, I found that it was Floating UI that was causing the problem. That led me to the documentation for the
When I reviewed the anchorable code for the select component, I found that the anchorable was never actually cleaned up when it was hidden. popoverable.getState() && anchorable.reposition() The solutionThe solution was to ensure that if the popover state changes to closed, that we clean up the anchorable. popoverable.getState() ? anchorable.reposition() : anchorable.cleanup() I also remembered that there was another similar issue with select dropdowns at the bottom of the page repositioning wrong on a reopen. When I tested that, this fix also fixes that issue. |
Nice! 2-for-1! Thanks, @joshhanley for the explanation and the fix 👍 |
Thanks for the quick fix and explanation! |
Flux version
1.1.2
Livewire version
3.5.12
What is the problem?
When clicking on a select with
variant="listbox"
in a modal, the page behind the modal scrolls to the top. This happens in both flyout and regular modals.CleanShot.2025-01-06.at.22.22.07.mp4
Code snippets
How do you expect it to work?
The background should not change when clicking select boxes within modals
Please confirm (incomplete submissions will not be addressed)
The text was updated successfully, but these errors were encountered: