GooseUI

Components

useHorizontalWheel

New

useHorizontalWheel turns the vertical mouse wheel into horizontal scrolling of a row: carousels, tabs, card strips. Mouse users can scroll the row without Shift, and it never traps the page.

Preview

Hover the row and turn the mouse wheel. At either end the page scrolls again.

Mountain cabin
$80 / night
Lake house
$95 / night
City loft
$110 / night
Beach hut
$125 / night
Forest lodge
$140 / night
Desert camp
$155 / night
River barge
$170 / night
Island villa
$185 / night
Ski chalet
$200 / night
Garden studio
$215 / night

Installation

npx shadcn@latest add @gooseui/use-horizontal-wheel
pnpm dlx shadcn@latest add @gooseui/use-horizontal-wheel
yarn dlx shadcn@latest add @gooseui/use-horizontal-wheel
bunx --bun shadcn@latest add @gooseui/use-horizontal-wheel

Usage

import { useHorizontalWheel } from "@/hooks/use-horizontal-wheel"

export function CardRow({ items }: { items: Item[] }) {
  const ref = useHorizontalWheel()

  return (
    <div ref={ref} className="flex gap-4 overflow-x-auto">
      {items.map((item) => (
        <Card key={item.id} item={item} />
      ))}
    </div>
  )
}

Examples

Instant scrolling

By default the row eases toward the target. Turn smoothing off to move by the exact wheel step. With prefers-reduced-motion it is off anyway.

const ref = useHorizontalWheel({ smooth: false })

Pause while dragging

Use disabled to switch the behavior off without detaching the ref, for example while a drag is in progress.

const [dragging, setDragging] = useState(false)
const ref = useHorizontalWheel({ disabled: dragging })

Parameters

NameTypeDefaultDescription
options.smoothbooleantrueEase toward the target position. Ignored with prefers-reduced-motion
options.disabledbooleanfalseLeave the wheel alone

Returns

NameTypeDescription
refRefCallback<T>Callback ref for the scrollable element

Features

  • Releases at the edges. At the start or end of the row the wheel scrolls the page as usual
  • Leaves trackpads alone. Gestures with a horizontal part already scroll the row natively and are not touched
  • Respects modifiers. Shift + wheel and Ctrl + wheel (zoom) keep the browser behavior
  • Line and page modes. Wheel deltas in lines or pages are converted to pixels