Skip to main content
A headless hook for implementing drag-to-scroll functionality with scroll buttons.

Import

Usage

Hook Options

'horizontal' | 'vertical' | 'both'
default:"horizontal"
The direction in which scrolling is allowed
  • horizontal - Only scroll horizontally
  • vertical - Only scroll vertically
  • both - Scroll in both directions
'item' | number
default:"item"
Amount to scroll when using navigation buttons
  • "item" - Scroll by the width/height of the first child element
  • number - Scroll by a fixed pixel amount
'allScreens' | 'desktopOnly' | 'mobileAndTabletOnly'
default:"allScreens"
Device usage constraints for drag behavior
  • allScreens - Drag works on all devices
  • desktopOnly - Drag works only on desktop (width >= 768px)
  • mobileAndTabletOnly - Drag works only on mobile/tablet (width < 768px)
object
Custom class names for drag scroll parts
  • base?: string - Root container classes
  • item?: string - Item classes
boolean
default:false
Whether to disable the internal state subscription for setting data attributesThis is useful if you want to subscribe to the state yourself

Return Value

propGetters

Object containing prop getter functions for each component part.
function
Returns props for the scrollable container element
Returns:
  • Element props with scroll behavior classes
  • ref callback for container registration
  • Data attributes: data-scope="drag-scroll", data-part="root", data-dragging (when dragging)
function
Returns props for individual scroll items
Returns:
  • Element props with snap-center classes
  • Data attributes: data-scope="drag-scroll", data-part="item"
function
Returns props for the previous/back scroll button
Returns:
  • Button props with click handler to scroll backward
  • disabled when at the start of scroll
  • Data attributes: data-scope="drag-scroll", data-part="back-button", data-disabled
function
Returns props for the next/forward scroll button
Returns:
  • Button props with click handler to scroll forward
  • disabled when at the end of scroll
  • Data attributes: data-scope="drag-scroll", data-part="next-button", data-disabled

containerRef

React.RefObject<TElement | null>
Ref object containing the scrollable container element

storeApi

StoreApi<DragScrollStore<TElement>>
Store API for accessing and subscribing to drag scroll state

useDragScrollStore

function
Hook for subscribing to specific slices of the drag scroll state

disableInternalStateSubscription

boolean
The resolved value of the disableInternalStateSubscription option

Types

DragScrollStore

DragScrollState

DragScrollActions

UseDragScrollProps

UseDragScrollResult