You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apply virtualization to a long lists (horizontal, vertical, maybe grid) of elements.
Description
I've built virtualization using react-virtual previously. The component exports parts that apply the required styles to make virtualization work, which look something like:
interfaceVirtualizerItemPropsextendsPick<VirtualItem,'size'|'start'>,ComponentProps<'div'>{asChild?: boolean;disableDynamicSize?: boolean;}exportconstRowVirtualizerItem=forwardRef<ElementRef<'div'>,VirtualizerItemProps>(({ asChild, disableDynamicSize, size, start, className, ...props},ref)=>{constComp=asChild ? Slot : 'div';return(<Compref={ref}style={{height: disableDynamicSize ? `${size}px` : undefined,transform: `translateY(${start}px)`,}}className={cn('absolute left-0 top-0 w-full',className)}{...props}/>);});RowVirtualizerItem.displayName='RowVirtualizerItem';// ...exportconstSelectScrollAreaVirtualizedViewport=({
children,
position ='popper',
virtualizerProps,
...props}: SelectScrollAreaVirtualizedViewportProps)=>{constparentRef=React.useRef<React.ElementRef<typeofSelectScrollAreaViewport>>(null);constvirtualizer=useVirtualizer({getScrollElement: ()=>parentRef.current,
...virtualizerProps,});return(<SelectScrollAreaViewportref={parentRef}position={position}{...props}><RowVirtualizerContainersize={virtualizer.getTotalSize()}>{virtualizer.getVirtualItems().map((virtualItem)=>(<RowVirtualizerItemasChildkey={virtualItem.key}size={virtualItem.size}start={virtualItem.start}// Dyanmic row height implementation. For more information, see https://tanstack.com/virtual/latest/docs/api/virtualizer#measureelement-1.data-index={virtualItem.index}ref={virtualizer.measureElement}>{children(virtualItem,virtualizer)}</RowVirtualizerItem>))}</RowVirtualizerContainer></SelectScrollAreaViewport>);};
However, I thought we can make the API better. Currently was thinking to wrap Virtual Grid to provide a more declarative and elegant API, which supports Horizontal, Vertical, or both using Grid.
The component should also support composition via asChild so that we can compose it with Select and Combobox later if needed.
Virtualizer
Apply virtualization to a long lists (horizontal, vertical, maybe grid) of elements.
Description
I've built virtualization using
react-virtual
previously. The component exports parts that apply the required styles to make virtualization work, which look something like:However, I thought we can make the API better. Currently was thinking to wrap
Virtual Grid
to provide a more declarative and elegant API, which supports Horizontal, Vertical, or both using Grid.The component should also support composition via
asChild
so that we can compose it withSelect
andCombobox
later if needed.Anatomy
Libraries / Hooks
react-virtual
.The text was updated successfully, but these errors were encountered: