Skip to content
CraftDocsPlayground
Type to search
↑↓Navigate↵SelectEscClose
Home
Home
Changelog
What's New
Guide
Guide
Getting Started
Principles
Styling Components
Theme System
Working with AI
Foundations
All Tokens
Color
Elevation
Icons
Illustrations
Motion
Shape
Spacing
Typography
Libraries
Libraries
@xds/cli
@xds/core
Themes
Themes
Chocolate Theme
Theme: daily
Default Theme
Gothic Theme
Theme: matcha
Neutral Theme
Stone Theme
Components
Components
AppShell
AspectRatio
Avatar
Avatar
AvatarStatusDot
Badge
Banner
Breadcrumbs
BreadcrumbItem
Breadcrumbs
Button
Button
IconButton
ToggleButton
ToggleButtonGroup
Calendar
Card
Carousel
Chat
ChatComposer
ChatComposerDrawer
ChatComposerInput
ChatComposerTokenElement
ChatDictationButton
ChatLayout
ChatLayoutScrollButton
ChatMessage
ChatMessageBubble
ChatMessageList
ChatMessageMetadata
ChatSendButton
ChatSystemMessage
ChatTokenizedText
ChatToolCalls
Checkbox
CheckboxInput
CheckboxList
CheckboxListItem
ClickableCard
Code
CodeBlock
Collapsible
Collapsible
CollapsibleGroup
useXDSCollapsible
CommandPalette
CommandPalette
CommandPaletteEmpty
CommandPaletteFooter
CommandPaletteGroup
CommandPaletteInput
CommandPaletteItem
CommandPaletteList
DateInput
Dialog
AlertDialog
Dialog
DialogHeader
useXDSImperativeAlertDialog
useXDSImperativeDialog
Divider
DropdownMenu
DropdownMenu
DropdownMenuItem
EmptyState
Field
Field
FieldLabel
FieldStatus
Heading
HoverCard
HoverCard
useXDSHoverCard
Icon
Kbd
Layout
Center
FormLayout
Grid
GridSpan
HStack
Layout
LayoutContainer
LayoutContent
LayoutFooter
LayoutHeader
LayoutPanel
Section
StackItem
VStack
Link
List
List
ListItem
Markdown
MetadataList
MetadataList
MetadataListItem
MobileNav
MoreMenu
NavHeadingMenu
NavIcon
NumberInput
OverflowList
Pagination
Popover
Popover
useXDSPopover
PowerSearch
ProgressBar
Radio
RadioList
RadioListItem
Resizable
ResizeHandle
useXDSResizable
SegmentedControl
SegmentedControl
SegmentedControlItem
SelectableCard
Selector
MultiSelector
Selector
SelectorOption
SideNav
SideNav
SideNavCollapseButton
SideNavHeading
SideNavItem
SideNavSection
Skeleton
Slider
Spinner
StatusDot
Switch
Table
BaseTable
Table
TableCell
TableHeaderCell
TableRow
useXDSTableColumnSettings
useXDSTablePagination
useXDSTableSelection
useXDSTableSelectionState
useXDSTableSortable
Tabs
Tab
TabList
TabMenu
Text
TextArea
TextInput
Thumbnail
TimeInput
Timestamp
Toast
Toast
useXDSToast
Token
Tokenizer
Toolbar
Tooltip
Tooltip
useXDSTooltip
TopNav
TopNav
TopNavHeading
TopNavItem
TopNavMegaMenu
TopNavMegaMenuFeaturedCard
TopNavMegaMenuItem
TopNavMenu
TreeList
Typeahead
BaseTypeahead
Typeahead
TypeaheadItem
Utilities
Utilities
LinkProvider
MediaTheme
SyntaxTheme
Theme
useClickableContainer
useEntryAnimation
useFocusTrap
useGridFocus
useImageMode
useInputContainer
useListFocus
useMediaQuery
useOverflow
useScrollLock
useScrollOverflow
useXDSLayer
useXDSStreamingText
GitHub Pages
useOverflow@xds/core v0.0.13 · useOverflow

Usage

Measures children rendered in a hidden container to determine how many fit in the available width without flickering. Uses ResizeObserver to react to container size changes. The measurement container should hold all items plus an optional overflow indicator element (identified by a data-overflow-indicator attribute).
ts
import {useOverflow} from '@xds/core/hooks'

Best practices

GuidancePractices
DoRender all items into the measureRef container (hidden) and only the first visibleCount items into the containerRef container (visible).
DoInclude an overflow indicator (e.g., "+N more" button) as the last child of the measurement container with a data-overflow-indicator attribute.
Don'tUse for vertical overflow — this hook measures horizontal width only.

Parameters

ParamTypeDescription
itemCountrequired
numberTotal number of items to measure for overflow.
options
UseOverflowOptionsConfiguration object for overflow behavior.
options.gap
number (default: 0)Gap between items in pixels. Used in width calculations.
options.minVisibleItems
number (default: 0)Minimum number of items to always show, even if they don't fit.
options.collapseFrom
'start' | 'end' (default: 'end')Which end to collapse items from.
options.behavior
'observeParent' | 'observeSelf' (default: 'observeSelf')Which element to observe for overflow calculations. 'observeParent' uses the container's parent element width, allowing the visible container to remain content-sized.

Returns

FieldTypeDescription
containerRefReact.RefCallback<HTMLElement>Ref callback to attach to the visible container element.
measureRefReact.RefCallback<HTMLElement>Ref callback to attach to the hidden measurement container that holds all items.
visibleCountnumberNumber of items that fit in the visible container.
hasOverflowbooleanWhether any items are overflowing (visibleCount < itemCount).