Keep scroll position when picking a weapon on the front page

This commit is contained in:
Kalle
2026-10-23 18:44:03 +03:00
parent 428efeea5b
commit ac4ac95082
4 changed files with 12 additions and 1 deletions

View File

@@ -11,12 +11,14 @@ type WeaponPoolBannerTarget =
| {
weaponHref: (weaponId: MainWeaponId) => string;
defaultShouldRevalidate?: boolean;
preventScrollReset?: boolean;
onWeaponPress?: never;
}
| {
onWeaponPress: (weaponId: MainWeaponId) => void;
weaponHref?: never;
defaultShouldRevalidate?: never;
preventScrollReset?: never;
};
/** Highlighted row of quick links (or quick picks) to the weapons of the user's match profile weapon pool. */
@@ -73,6 +75,7 @@ export function WeaponPoolBanner({
key={weaponId}
to={target.weaponHref(weaponId)}
defaultShouldRevalidate={target.defaultShouldRevalidate}
preventScrollReset={target.preventScrollReset}
className={styles.weapon}
>
{image}

View File

@@ -70,7 +70,10 @@ export function SearchResultsListBox({
ref.current = element;
}
if (element && autoFocus === "first") {
element.querySelector<HTMLElement>('[role="option"]')?.focus();
// the parent dialog isn't open yet when this ref attaches, so a plain focus would scroll the page to it
element
.querySelector<HTMLElement>('[role="option"]')
?.focus({ preventScroll: true });
}
}}
role="listbox"

View File

@@ -357,6 +357,7 @@ function DiscoverFeatures() {
})
}
defaultShouldRevalidate={false}
preventScrollReset
/>
) : null}
<nav className={styles.discoverGrid}>

View File

@@ -0,0 +1,4 @@
---
type: bug
---
Clicking a weapon under "Your weapons" on the front page no longer scrolls the page to the top