fix(ui): prevent scroll jump on model card click caused by sort dropdown focus

The document-level click handler in SortDropdown.js called trigger.focus()
unconditionally on every click outside the sort group. When a model card
was clicked to open the modal, focus() triggered scrollIntoView on the
.sort-trigger button, perturbing .page-content.scrollTop and causing the
card grid to jump up a few pixels.

The same interference also broke the back-to-top smooth-scroll animation:
frame-by-frame focus/scroll perturbations caused VirtualScroller to
schedule repeated re-renders, interrupting the compositor-thread scroll.

Fix: only return focus to the trigger when the dropdown was actually open,
so ordinary page clicks (e.g. clicking a model card) never force focus.
This commit is contained in:
Will Miao
2026-06-26 19:40:12 +08:00
parent 8a6d23f9c7
commit 09c2445ac9

View File

@@ -230,8 +230,12 @@ export function initSortDropdown(select) {
// Close dropdown when clicking outside
document.addEventListener('click', (event) => {
if (!group.contains(event.target)) {
const wasOpen = group.classList.contains('active');
close();
trigger.focus();
// Only return focus to the trigger when the dropdown was actually
// open — avoids forcing scrollIntoView on every page click (which
// causes the scroll container to jump when clicking a model card).
if (wasOpen) trigger.focus();
}
});