Overview
TheuseDragScroll hook provides mouse drag-to-scroll behavior for horizontal or vertical scrollable containers. It’s completely headless and unstyled, giving you full control over the UI while handling all the complex drag, scroll, and navigation logic.
Use Cases
- Horizontal scrolling galleries and carousels
- Product listing rows
- Tab navigation with many items
- Timeline components
- Mobile-style swipeable lists on desktop
- Image galleries and media browsers
Installation
The DragScroll hook is included with the UI package:Basic Usage
API
useDragScroll Options
orientation
orientation
The scroll direction.
"horizontal"(default) - Scroll left/right"vertical"- Scroll up/down"both"- Scroll in both directions
scrollAmount
scrollAmount
Distance to scroll when using navigation buttons.
"item"(default) - Scroll by first child’s width/heightnumber- Scroll by fixed pixel amount
usage
usage
Device constraints for drag behavior.
"allScreens"(default) - Works on all devices"desktopOnly"- Drag only on desktop (768px and above)"mobileAndTabletOnly"- Drag only on mobile/tablet (below 768px)
classNames
classNames
Custom CSS classes.
base- Applied to root containeritem- Applied to each item
disableInternalStateSubscription
disableInternalStateSubscription
Disable automatic data-attribute updates (default:
false).
Set to true if you want to subscribe to state manually.Return Value
Prop Getters
getRootProps
Props for the scrollable container.ref- Container ref callbackclassName- Merged classes including drag cursor stylesdata-scope="drag-scroll"data-part="root"data-dragging- Present when actively dragging (if state subscription enabled)
getItemProps
Props for each scrollable item.className- Includes snap-center stylesdata-scope="drag-scroll"data-part="item"
getBackButtonProps
Props for the previous/back navigation button.type="button"onClick- Scrolls to previous item/sectiondisabled- Auto-disabled when can’t scroll backaria-label="Scroll back"data-disabled- Reflects disabled statedata-scope="drag-scroll"data-part="back-button"
getNextButtonProps
Props for the next/forward navigation button.type="button"onClick- Scrolls to next item/sectiondisabled- Auto-disabled when can’t scroll forwardaria-label="Scroll forward"data-disabled- Reflects disabled statedata-scope="drag-scroll"data-part="next-button"
Examples
Image Gallery
Product Carousel
Vertical Timeline
Desktop-Only Drag
Accessing State
Subscribe to internal state using the returned hook:Styling with Data Attributes
WhendisableInternalStateSubscription is false (default), the root element receives a data-dragging attribute:
The hook automatically manages scroll position tracking and updates button disabled states based on scroll position.
Accessibility
- Navigation buttons include proper
aria-labelattributes - Buttons are automatically disabled when scrolling is not possible in that direction
- The hook maintains focus management during interactions
- Keyboard users can still use native scroll with arrow keys and tab navigation