Repository navigation
v0.16.0
The eleventh Fluent UI v9 parity release: Phase 11 of the roadmap, tables and lists at data scale. DataGrid, List, Listbox, Combobox, Dropdown and the new FlatTree stay correct when most of their data is not rendered: a small built-in window (useVirtualWindow, passed as virtualWindow) renders the rows in view plus an overscan, with spacers for the others, while selection, select-all, sorting, the keyboard and the positions a screen reader announces (aria-rowcount and aria-rowindex, aria-setsize and aria-posinset) follow the data, and the focused row stays rendered when it is scrolled away. A DataGrid given items selects by its data instead of its rendered rows, its columns resize by pointer, touch and keyboard, and tables built from the static Table parts get headless state (useTableFeatures with sort, selection and column-sizing plugins, the generic useSelection) and Table.ResizeHandle. Listbox, Combobox and Dropdown take their options as data (items, renderOption). Windowing is fixed-size only and adds no dependency: an adapter over a virtualization library can implement the same VirtualWindow interface (the guide's "Data at Scale" chapter has one for @tanstack/react-virtual). It closes thirteen of the fourteen gaps of P11-01 to P11-04 (hook-1, hook-2, hook-3, hook-4, foundation-40, dg-3, dg-6, trh-1, virt-1, foundation-45, tree-9, list-6, combobox-7); table-2, a Table rendered from <div>s, stays open (windowing works on native table rows). Nothing public was removed, and no type narrows except UseGridNavigationResult, which gains two members, but a DataGrid with items changes how its selection behaves: read "Upgrading from 0.15" before upgrading.
Upgrading from 0.15
- A DataGrid with
items: selection follows the data. Select-all selects every selectable item ofitems, whether its row is rendered or not, and its checkbox shows the state of those items (checked when all are selected, mixed when some are); when all of them are selected, select-all removes only their ids, and a selected item whose selection is disabled keeps its state. A row click, Space and a row's control change one id and no longer drop the selected ids whose rows are not rendered, andonSelectedItemsChange(selectedItems, details)(same signature, row ids) now reports those ids too: an id of an item that is filtered out, on another page, outside the window or restored from storage by id stays selected until your code removes it. In 0.15 such ids were left out of the reported selection and of the select-all state, so the next change dropped them. In single mode the selected id is the first one given (0.15: the first one whose row is rendered), and newitemsdo not clear it. Select-all reports the ids outsideitemsfirst, then the selected ids ofitemsinitemsorder, so a grid that mounts sorted (defaultSortor a controlledsort) now reports them initemsorder, where 0.15 reported the sorted order. A grid built fromDataGrid.Rowchildren (noitems) keeps the 0.15 behaviour. isSelectionDisabled(item, index)tells a grid withitemswhich items cannot be selected, rendered or not: select-all skips them, and a rendered row takes it as thedisabledof its selection cell. Without it, an item is selectable unless its rendered row disables its selection cell (selectionCellProps.disabled,DataGrid.SelectionCell disabled), which only a rendered row can say: a grid with avirtualWindowpassesisSelectionDisabled, or select-all also selects the disabled items it does not render. A cell's owndisabledstill wins for its control, and a value that disagrees withisSelectionDisabledwarns in development.- Everything else is opt-in: windowing (
useVirtualWindow, andvirtualWindowon DataGrid, List, Listbox, Combobox and Dropdown),FlatTreeanduseFlatTree, the table hooks, the pickers' data mode (items) and resizable columns are new components, props and hooks. A component that uses none of them behaves as in 0.15, apart from item 1. - A windowed list needs a bounded height and a fixed item height. Its scroller (the DataGrid's scroll wrapper, the element of
containerProps; the List, Listbox or FlatTree element; the popup list of a Combobox or Dropdown has its own maximum height) needs a height or a maximum height, or the window measures the whole list and renders every item (DataGrid warns in development,DataGrid:virtual-window-height). Every item is exactly the window'sitemSizetall: the components set that height on each row, item and option after its ownstyle, and a windowed DataGrid's body cells drop their block padding and keep their text on one line, so the content must fit. - Development warnings a 0.15 grid can now log: in a grid with
items, aDataGrid.Rowwhose ownrowIddiffers from its item's id (DataGrid.Row:row-id-mismatch), or aDataGrid.Rowchild of the body whoserowIdis no item's id (DataGrid.Row:row-id-outside-items): select-all and its checkbox use the ids fromgetRowId, so such rows are outside them. Pass agetRowIdthat returns the rows' ids. Withitems, the text ofDataGrid:single-several-selectedsays that only the first id is selected (key unchanged). A test that spies onconsole.warnasserts them. - Types:
UseGridNavigationResulthas two new members,activeRowIndexandpendingRowIndex(alwaysnullwithout the newmodeloption): a hand-built value of it (a test mock) adds them.ListboxOptionElementPropsgains optionalaria-posinset,aria-setsizeandstyle, which an option component of yours onuseListboxOptionreceives in a data-mode list (the position) and in a windowed list (its height): spread them, and mergestyleafter your own.DataGridLabelsgainsresizeColumnandcolumnWidth.
Added
useVirtualWindow(options)(virt-1,foundation-45), a window over a long list of fixed-height items:itemSize(pixels; every item has it),overscan(items rendered beyond each edge; by default enough for 240 pixels and at least 6, so 9 items of 28 pixels and 8 of 32),initialViewportSize(the viewport assumed on the server, in the first render and while the scroller measures 0;480) andscrollPaddingStart(the height of a sticky header over the rows, whichscrollToIndexplaces rows below). It returns aVirtualWindow:itemSize,scrollRef(the scrolling element's callback ref),layout(count, { keep })(theVirtualEntrylist to render,{ kind: 'item', index }and{ kind: 'spacer', size, key }, a pure function called during render;keepholds indexes outside the view, the focused row) andscrollToIndex(index, { align })(auto, the least scroll that shows the item,start,center,end; it moves the window in the same update, a request made before the scroller attaches is applied when it does, and once more when the scroller first changes height, a popup that positioning shrinks, unless it was scrolled first). The window re-renders when the first row in view or the viewport height changes, not per scroll event: a passivescrolllistener read once per animation frame and aResizeObserver. Pass it to a component'svirtualWindow: the component lays the window out itself, since only it knows which item it must keep rendered. MergescrollRefwith your refs or destructure it (ref={virtualWindow.scrollRef}fails the React Compiler's lint). Fluent's closest counterpart is its deprecatedVirtualizer; an object of your own that implementsVirtualWindow(an adapter over@tanstack/react-virtual, guide) works in every component.- DataGrid
virtualWindow(virt-1), withitemsandcolumnsand the body rows rendered from them: only the body rows in view render, with spacer rows (<tr aria-hidden="true" data-virtual-spacer>,wave-data-grid__spacer) for the others. The scroll wrapper (containerProps) is the scroller and needs a bounded height; the header sticks at its top (pass the header's height asscrollPaddingStart); the columns are laid out from widths, so they never change as rows come and go. The keyboard moves by the data: ArrowUp/ArrowDown, PageUp/PageDown (10 rows) and Ctrl+Home/Ctrl+End scroll a target row that is not rendered into the window and focus it once it renders, the focused row stays rendered while it is scrolled away, and when a sort or newitemsmake the browser drop focus from a moved row, focus returns to the same row, or the rendered row nearest its place. The grid carriesaria-rowcount(the items plus the header rows), every rowaria-rowindex(header rows first, body rows in the sorted order) and every body rowdata-row-index; without a window none of them render. A focused row that the sticky header covers is scrolled below it (not for the focus a pointer press gives). - List
virtualWindowandcount(list-6), with a function child(index) => <List.Item …/>that the list calls for the rendered indexes only: the list element is the scroller (vertical scrolling is added; give it a bounded height), items carrydata-indexand their place in the whole list (aria-setsizeandaria-posinset, or in a grid,navigationMode="composite",aria-rowcounton the list andaria-rowindexon the rows), and spacers arearia-hidden<li>s (<div>s in a grid) withwave-list__spacer. Where the list navigates its items, the keys move by index over the whole list (the arrows wrap, PageUp/PageDown move ten items and stop at the ends, Home/End), scrolling the target into view before it is focused; the focused item stays rendered (also while focus is in a popup it opened) and is the Tab stop while focus is in the list; whencountdrops to or below the focused item, focus moves to the last item. Selection keeps the values of items that are not rendered. A selectable windowed list stays a listbox whatever its rendered items hold, unlessnavigationMode="composite"makes it a grid from the first render (an item with an action in a selectable windowed list without it warns). Typeahead matches the rendered items' labels only. - Data mode for Listbox, Combobox and Dropdown (
combobox-7):items(ListboxItem:value,label, and optionallytextValue,disabledandhidden) instead of option children, andrenderOption(item, state)(ListboxOptionRenderState:selected,active,indexamong the shown options; by default anOptionwith the item's label). The keys, typeahead, the selected labels and the Combobox filter come fromitems, also for a selected item whose option is not rendered, and every option carriesaria-posinsetandaria-setsizeamong the shown options (typing in a Combobox narrows both). A closed data-mode Combobox or Dropdown renders no options (its labels come fromitems), so its server HTML holds none either.virtualWindow(data mode only) renders the options in view plus an overscan, with<li>spacers (wave-listbox__spacer,wave-combobox__spacer,wave-dropdown__spacer): the Listbox element is the scroller (give it a bounded height; it drops its block padding while windowed), and a popup's list scrolls within its own 15rem maximum. Every option is exactlyitemSizetall (the defaultOptionwith one line of text is 32 pixels); the active option stays rendered, soaria-activedescendantalways names an element; a key or typed text that moves the active option moves the list and the window in the same update; opening a popup puts the active option, else the first selected one, in the middle of the list, and again once positioning has given the list its height on a short viewport. Option groups cannot be windowed (a development warning). - Windowed scrollers (of DataGrid, List, the three pickers and FlatTree) turn the browser's scroll anchoring off (the window lays the items out; FlatTree keeps its focused item in place itself when rows are inserted or removed above it), and one that holds the tab stop item is no Tab stop of its own: the DataGrid's scroll wrapper, a List that navigates its items and a FlatTree with a tab stop item get
tabIndex-1 (Firefox stops on a scroller otherwise), before your props, so atabIndexof yours wins. A plain windowed List (navigationModenone) keeps the browser's default, under which WebKit does not let the keyboard reach and scroll it: passtabIndex={0}or navigate its items (navigationMode="items"). onScrollToItem(index)onuseActiveDescendantanduseListbox: called first for every move that scrolls the active item into view (keys,setActiveValue, the fallback that becomes active; never a pointer highlight or ascroll: falsemove), with the item's index (foruseListbox, among the shown options), so a windowed list of your own passes(index) => virtualWindow.scrollToIndex(index, { align: 'auto' }). An element, when there is one, is then scrolled into view as before.FlatTreeanduseFlatTree(tree-9): a tree built from flat data that can render only the items in view.useFlatTree(items, options)takesFlatTreeItemDataitems (value,parentValue,itemType,label,disabled; listed in any order) and the nested Tree's state names (expandedItems,defaultExpandedItems,onExpandedItemsChange,checkedItems,defaultCheckedItems,onCheckedItemsChange(checkedItems, details),selectionMode), and returns aFlatTreeModel:visibleItems(VisibleFlatItem:item,level,position,setSize,parentValue,hasChildren,isBranch,expanded,index, and withselectionMode: 'multiple'checked),getItem,expand(a value or a list, one change),collapse,toggle,isExpanded,setCheckedandgetTreeProps(). Checks cascade as in the nested Tree. Unknown parents, cycles and duplicate values are development warnings.FlatTree(model,virtualWindow,renderItem,selectionMode,selected,current,onItemSelect) renders the visible items as siblingrole="treeitem"elements witharia-level,aria-setsize,aria-posinsetandaria-expanded, the chevron and the checkbox or radio of the nested Tree's items; Up/Down, Home/End, Right/Left (mirrored in right-to-left layouts), Enter, Space,*and typeahead over the visible labels come from the model. A disabled item is skipped by the keys and is neither activated, expanded nor checked by the user. A branch collapsed around the focused item from code moves focus to the branch.FlatTree.Item(FlatTreeItem) is the row the tree renders. The nestedTreeis unchanged.- Headless table state (
hook-1,hook-2,hook-3):useTableFeatures({ items, columns, getRowId }, plugins)(Fluent's call shape) with the plugin hooksuseTableSort(sort,defaultSort,onSortChange(sort, details), DataGrid'sDataGridSortshape),useTableSelection(selectionMode,selectedItems,defaultSelectedItems,onSelectedItemsChange(selectedItems, details)with row ids,isDisabled(item, index)) anduseTableColumnSizing(below). The state holdsgetRows()(TableRowData<T>:item,rowId,index, sorted by the sorted column'scompare),sort(value,setColumnSort,toggleColumnSort,getSortDirection),selection(selectedItems,allRowsSelected,someRowsSelectedover every selectable item,isRowSelected,toggleRow,selectRow,deselectRow,toggleAllRows,clearRows) andcolumnSizing, each slot inert without its plugin. The state follows the data, not the rendered rows: select-all keeps ids outsideitems. Each plugin fills its own slot, so the array's order does not matter; a feature given twice uses its last plugin, with a development warning. TypesTableFeaturesState,TableFeaturePlugin,TableRowData,TableSortState,TableSelectionState,TableColumnSizingState,TableResizeHandleBindings,UseTableFeaturesOptions,UseTableSortOptions,UseTableSelectionOptions. useSelection(options)(foundation-40): selection by id held outside the DOM (selectionMode,selectedItems,defaultSelectedItems,onSelectedItemsChange(selectedItems, details)withUseSelectionChangeDetails), returningselectedItems(aReadonlySetthat keeps its identity while the ids stay),isSelected,toggle,select,deselect,toggleAll(universe)(selects the universe, or removes only its ids; nothing in single mode) andclear. TypesUseSelectionOptions,UseSelectionResult.- Resizable columns (
dg-3): DataGridresizableColumnsgives each column's header cell a resize handle (Fluent's name), withcolumnsanditems. A pointer drag (mouse, touch or pen) moves the column's end edge, mirrored in right-to-left grids; from the keyboard, F2 on a header cell or its sort button moves focus to the handle (it adds no Tab stop to the grid), the arrow keys move the edge by 20 pixels (5 with Shift), Home sets the minimum, and Enter, Space or Escape return focus to the header, where Enter on a sortable header still sorts; a double click sets the column back to its initial width once a width is state.columnSizingOptions(ColumnSizingOption:minWidth, 80 by default, and the starting widthdefaultWidth, elseidealWidth, else 150),columnWidthsanddefaultColumnWidths(pixels bycolumnId) andonColumnWidthsChange(widths, details)(every column's width at each step of a drag or key press;TableColumnWidthsChangeDetails:columnId,width,event, Fluent'sonColumnResizedata). Any of the width props lays the columns out from widths (a<colgroup>and a fixed table layout) with or without handles, and the cells then truncate their text. Until a width is state the grid is 100% wide and at least as wide as its columns; the first change takes the widths the columns are drawn at, so nothing jumps, and from then on the grid is exactly as wide as its columns. There is no auto-fit and no maximum width. The grid carriesdata-resizingwhile a handle drags;labels.resizeColumn("Resize column") andlabels.columnWidth(width)("N pixels") name and describe the handles. Table.ResizeHandle(TableResizeHandle,TableResizeHandleProps;trh-1), the handle DataGrid renders, for theasideof a positionedTable.HeaderCell: a verticalrole="separator"witharia-valuenow,aria-valuemin,aria-valuemax(withmaxWidth) andaria-valuetext, takingwidth,minWidth(0),maxWidth(End sets it),onResize(width, details)(whole pixels, at most once per animation frame while dragging),onReset(details)(the double click),onLeave()(Escape, or Enter or Space released),label("Resize column") andvalueText(width). It is a Tab stop (tabIndex0) for a static table, keeps no width of its own, carriesdata-draggingwhile it drags anddata-grid-auxiliary.useTableColumnSizing(options)(hook-4;columnSizingOptions,columnWidths,defaultColumnWidths,onColumnWidthsChange;UseTableColumnSizingOptions) fillscolumnSizing:columnWidths,isSized,getColumnWidth,setColumnWidth, and the props to spread,getTableProps(),getColumnProps(columnId)(a<col>) andgetResizeHandleProps(columnId)(aTable.ResizeHandle, withonReset).useGridNavigationmodel(GridNavigationModel:rowCount,headerRowCount,scrollToRow(index)) for a grid whose data rows are rendered in part (each rendered row carriesdata-row-index): the vertical keys move by the data, a target row that is not rendered is asked for withscrollToRowand focused when it renders, and the new resultsactiveRowIndexandpendingRowIndexname the rows to keep rendered. Auxiliary widgets: a widget that carriesdata-grid-auxiliary(the resize handle) is never a cell's target, so the cell's target stays its other widget, and F2 on the cell or on its target widget enters interaction mode at it. Without a model or an auxiliary widget the hook behaves as in 0.15.- DataGrid
isSelectionDisabled(item, index)("Upgrading from 0.15", 2). - Types
UseVirtualWindowOptions,VirtualWindow,VirtualEntry,UseSelectionOptions,UseSelectionResult,UseSelectionChangeDetails,ColumnSizingOption,TableColumnWidthsChangeDetails,UseTableColumnSizingOptions,TableResizeHandleProps,GridNavigationModel,ListboxOptionRenderState,FlatTreeProps,FlatTreeItemProps,UseFlatTreeOptions,FlatTreeModel,FlatTreeItemData,VisibleFlatItemandCheckState, and the table-state types above. - Stable class names:
flatTreeClassNames(root,spacer),flatTreeItemClassNames(root,row,expandIcon,indicator,label) andtableResizeHandleClassNames; new keysspacerondataGridClassNames,listClassNames,listboxClassNames,comboboxClassNamesanddropdownClassNames, andresizeHandleondataGridHeaderCellClassNames(a DataGrid's handle carries both classes). - Development warnings (keys):
useVirtualWindow:item-size,useTableFeatures:duplicate-plugin,useTableFeatures:plugin-count,useTableFeatures:duplicate-row-id,DataGrid:virtual-window-requires-items,DataGrid:virtual-window-height,DataGrid:resizable-columns-require-columns,DataGrid:selection-disabled-mismatch,DataGrid.Row:row-id-mismatch,DataGrid.Row:row-id-outside-items,List:virtual-window-children,List:virtual-window-actions, and for each ofListbox,ComboboxandDropdown:items-and-children,:render-option-without-items,:virtual-window-requires-itemsand:virtual-window-groups;useFlatTree:unknown-parent,useFlatTree:cycle,useFlatTree:duplicate-value,FlatTree:name,FlatTree:selection-mode,FlatTree:selected-with-multiple,FlatTree:single-without-selected. - Stories: DataGrid
Paging(selection kept across pages),Resizable,ResizableControlledandTenThousandRows;Components/Table/Features(a static Table on the hooks, withTable.ResizeHandle); ListWindowed;DataModeandTenThousandOptionson Listbox, Combobox and Dropdown; FlatTreeDefault,CheckableandFiveThousandNodes.
Changed
Behaviour
- DataGrid selection with
itemsfollows the data ("Upgrading from 0.15", 1 and 2), and the server HTML and first client render of a grid withitemsshow the select-all state from the data (0.15 rendered it unchecked until the rows had registered).
DOM structure
- The markup of 0.15 is unchanged without the new props (apart from that select-all state). The new props add the spacer elements (
data-virtual-spacer,aria-hidden),aria-rowcount,aria-rowindexanddata-row-indexof a windowed DataGrid,data-index,aria-setsizeandaria-posinseton a windowed List's items,aria-posinsetandaria-setsizeon the options of a data-mode picker, a<colgroup>in a DataGrid laid out from widths, and the resize handles (a header cell with a handle getsaria-labelledby, so its name stays its label).
Types
UseGridNavigationResultgainsactiveRowIndexandpendingRowIndex,ListboxOptionElementPropsgains three optional members andDataGridLabelstwo ("Upgrading from 0.15", 6); every other change is a new optional prop or a new export.
Development messages
DataGrid:single-several-selectednames the first given id in a grid withitems("Upgrading from 0.15", 5).
Dev gates
verify-dist: an import of onlyuseVirtualWindowstays withinVIRTUAL_BUDGET(4,415 bytes minified and 2,048 gzip) and imports nothing butreact, and an import of onlyDataGridwithinDATA_GRID_BUDGET(86,990 and 29,431 bytes, 25% over its first 0.16 measurement) and the package's own dependencies; imports of onlyuseVirtualWindowor onlyuseSelectionhold no component, one of onlyDataGridno FlatTree code, one of onlyFlatTreeno DataGrid code, one of onlyTreethe moved cascade and no other 0.16 module, and imports of onlyButtonor onlyMessageBarno 0.16 module at all. The CLI prints the DataGrid-only, Tree-only, Button-only and MessageBar-only sizes against 0.15.0 at every build. The module-only list gains the 0.16 seams.
Deprecated
- Nothing new is deprecated.
Fixed
- DataGrid selection and select-all covered only the rendered rows (
dg-6). In a grid withitems, ids of rows that were not rendered dropped out at the next change, which broke filtering and paging, and select-all knew only the rendered rows; both now cover every item ("Upgrading from 0.15", 1). - A List dropped the selected values of the items it did not render (
list-6): a windowed List keeps them, andonSelectionChangereports them. A List without a window still drops the values of the items it no longer renders, as in 0.15.
Size
Against 0.15.0 as published on npm, measured with this release's build tools the way 0.15.0 was (verify-dist's probe: minified Vite builds of an entry that imports one name from dist/index.mjs, bare imports external, gzip by node:zlib). Sizes are in bytes:
| Import | 0.15.0 | 0.16.0 |
|---|---|---|
dist/styles.css (as built, KiB) |
95.3 KiB (15.3 KiB gzip) | 96.6 KiB (15.4 KiB gzip) |
An import of only useVirtualWindow (new) |
— | 3,868 (1,817 gzip) |
An import of only useSelection (new) |
— | 2,706 (1,290 gzip) |
An import of only useTableFeatures (new) |
— | 2,352 (1,190 gzip) |
An import of only useFlatTree (new) |
— | 6,637 (2,754 gzip) |
An import of only FlatTree (new) |
— | 18,913 (7,103 gzip) |
An import of only DataGrid |
48,403 (16,520 gzip) | 70,070 (23,708 gzip) |
An import of only Table |
24,734 (8,567 gzip) | 28,790 (9,945 gzip) |
An import of only List |
36,749 (12,989 gzip) | 41,916 (14,718 gzip) |
An import of only Listbox |
38,502 (13,893 gzip) | 41,902 (15,048 gzip) |
An import of only Combobox |
65,772 (23,005 gzip) | 69,538 (24,238 gzip) |
An import of only Dropdown |
61,610 (21,420 gzip) | 65,370 (22,718 gzip) |
An import of only Tree |
47,248 (16,201 gzip) | 47,248 (16,196 gzip) |
An import of only Button |
11,195 (3,855 gzip) | 11,195 (3,855 gzip) |
An import of only MessageBar |
26,831 (9,312 gzip) | 26,831 (9,312 gzip) |
- The window is small:
useVirtualWindowwith its layout core is 1,817 bytes gzip, under the spec's ceiling of 2 KiB (VIRTUAL_BUDGETgates it at 2,048). - The DataGrid-only import grew by 44.8% (43.5% gzip), from 48,403 to 70,070 bytes (16,520 to 23,708 gzip): eight new modules hold the selection store and core, column sizing and the resize handle, the window support and the header and context split. Every DataGrid user carries them, windowed or not.
DATA_GRID_BUDGETgates the import at 25% over its first 0.16 measurement (69,592 bytes, 23,545 gzip): 86,990 bytes minified and 29,431 gzip, 16,920 and 5,723 bytes above the size it has now. A larger DataGrid needs a deliberate raise. - Tree-only, Button-only and MessageBar-only imports are unchanged: a Tree-only import holds one module more, the moved cascade (the minified code is the same size, 5 bytes less gzip), and the Button-only and MessageBar-only imports are byte for byte 0.15.0's;
verify-distgates that they hold none of the 0.16 modules. - The pickers gain their data mode (
Option.data), List its window support, and TableTable.ResizeHandleand the direction helpers it uses.