TanStackT
TanStack12mo ago
8 replies
popular-magenta

resetScroll={false} only works on first click

I am super confused here. The first click on one of these tabs works correctly (page doesnt scroll to the top), but all subsequent clicks scroll to the top.

Am I doing something wrong?

The same was happening when I tested with Link components outside of this Tabs component as well, so I think I've isolated it to not be an issue with this component

export function ProductTypeNav({ projectId }: { projectId: number }) {
  const productTypes = ProductTypeSchema.options;
  const currentProductType = useSearch({
    from: "/p/$projectId/settings/products",
    select: (search) => search.productType,
  });

  const navigate = useNavigate();
  return (
    <>
      {/* Desktop */}
      <Tabs
        value={currentProductType ?? undefined}
        className="hidden lg:block"
        onValueChange={(value) => {
          navigate({
            to: "/p/$projectId/settings/products",
            resetScroll: false,
            search: {
              productType: value as ProductType,
            },
            params: {
              projectId,
            },
          });
        }}
      >
        <TabsList className="flex gap-2">
          {productTypes.map((pt) => (
            <TabsTrigger value={pt} key={pt}>
              {pt}
            </TabsTrigger>
          ))}
        </TabsList>
      </Tabs>
)
}
Was this page helpful?