生态产品多个设计器现已发布候选版本

查看生态总览
Skip to content

Virtualizer ​

Data display component. This page is the API reference, generated from the source code. Usage guidance and live examples are on the Chinese page.

Anatomy ​

Parts in bold are required.

data-scope="virtualizer": root · viewport · content · item

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-virtualizer>
Vue componentsXhVirtualizerContent XhVirtualizerItem XhVirtualizerRoot XhVirtualizerViewport
ComposableuseVirtualizer
State machinevirtualizerMachine
Skin@xihan-ui/styles/virtualizer.css

Props ​

PropTypeRequired
countnumber
estimateSizenumber | ((index: number) => number)
overscannumber
horizontalboolean
gapnumber
getItemKey(index: number) => string | number
onRangeChange(details: VirtualizerRangeChangeDetails) => void
scrollMarginnumber
paddingStartnumber
paddingEndnumber
lanesnumber
viewportTabIndexnumber
scrollContainerVirtualizerScrollContainer
anchorVirtualizerAnchor
stickyIndicesnumber[]
estimateFromMeasuredboolean

Events ​

Custom elements put the payload in detail; Vue emits an event of the same name.

EventPayload
range-changeVirtualizerRangeChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhVirtualizerRootdefaultVirtualizerRootSlotProps

React adapter props ​

Only the props each component declares itself: DOM attributes inherited from ComponentPropsWithRef are left out, and root props already listed in the Props table are not repeated. The Vue counterpart is the slot table above.

React componentPropTypeRequired
XhVirtualizerItemvaluenumber | stringYes
XhVirtualizerItemmeasureboolean
XhVirtualizerRootchildrenSlotChildren<VirtualizerRootSlotProps>

State ​

The following names are internal to the state machine.

States: idle · scrolling

Events: SCROLL.START · SCROLL.END · MEASURE

connect API ​

getXxxProps() returns the host attributes of the matching part.

MemberType
virtualItemsreadonly VirtualizerItemState[]
totalSizenumber
startIndexnumber | null
endIndexnumber | null
horizontalboolean
lanesnumber
scrollingboolean
collectionVirtualizerCollectionVirtualizer
scrollToIndex(index: number, options?: VirtualizerScrollToOptions) => void
measureElement(element: HTMLElement | null) => void
measure() => void
registerItemElement(index: number, element: HTMLElement | null) => void
getRootProps() => T['element']
getViewportProps() => T['element']
getContentProps() => T['element']
getItemProps(props: VirtualizerItemProps) => T['element']

Accessibility ​

Keyboard ​

Specification: W3C APG. Each row is a stable behavior id that the conformance tests cover; the conditions and effects are described on the Chinese page.

No keyboard interaction: the component takes no focus, or focus behavior comes entirely from native elements.

Style reference ​

Skin ​

@xihan-ui/styles/virtualizer.css is written against [data-scope="virtualizer"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-virtualizer in place of data-scope (same specificity) and sits in the xihan.components layer. Put overrides in xihan.overrides; the part selectors work as usual.

Data attributes ​

Produced by connect; valueless attributes are omitted while their condition does not hold.

PartAttributeValue
rootdata-orientation'horizontal' | 'vertical'
rootdata-scroll-containerundefined | props.scrollContainer
rootdata-scrolling'' (present only while the condition holds)
viewportdata-anchor'end' | undefined
viewportdata-orientation'horizontal' | 'vertical'
viewportdata-scroll-containerundefined | props.scrollContainer
contentdata-orientation'horizontal' | 'vertical'
itemdata-fixed'' (present only while the condition holds)
itemdata-indexprops.index
itemdata-laneitem.lane | undefined
itemdata-orientation'horizontal' | 'vertical'

CSS variables ​

The public override slots, generated from what the standalone skin actually consumes.

VariablePartCSS propertyStateDefault from
--xh-virtualizer-sticky-bgitembackgroundfixed--xh-bg-surface
--xh-virtualizer-sticky-layeritemz-indexfixed--xh-layer-sticky

Released under The MIT License