Skip to content

v0.16.0

Choose a tag to compare

@github-actions github-actions released this 29 Oct 15:55
· 321 commits to main since this release

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

  1. A DataGrid with items: selection follows the data. Select-all selects every selectable item of items, 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, and onSelectedItemsChange(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 new items do not clear it. Select-all reports the ids outside items first, then the selected ids of items in items order, so a grid that mounts sorted (defaultSort or a controlled sort) now reports them in items order, where 0.15 reported the sorted order. A grid built from DataGrid.Row children (no items) keeps the 0.15 behaviour.
  2. isSelectionDisabled(item, index) tells a grid with items which items cannot be selected, rendered or not: select-all skips them, and a rendered row takes it as the disabled of 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 a virtualWindow passes isSelectionDisabled, or select-all also selects the disabled items it does not render. A cell's own disabled still wins for its control, and a value that disagrees with isSelectionDisabled warns in development.
  3. Everything else is opt-in: windowing (useVirtualWindow, and virtualWindow on DataGrid, List, Listbox, Combobox and Dropdown), FlatTree and useFlatTree, 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.
  4. 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's itemSize tall: the components set that height on each row, item and option after its own style, and a windowed DataGrid's body cells drop their block padding and keep their text on one line, so the content must fit.
  5. Development warnings a 0.15 grid can now log: in a grid with items, a DataGrid.Row whose own rowId differs from its item's id (DataGrid.Row:row-id-mismatch), or a DataGrid.Row child of the body whose rowId is no item's id (DataGrid.Row:row-id-outside-items): select-all and its checkbox use the ids from getRowId, so such rows are outside them. Pass a getRowId that returns the rows' ids. With items, the text of DataGrid:single-several-selected says that only the first id is selected (key unchanged). A test that spies on console.warn asserts them.
  6. Types: UseGridNavigationResult has two new members, activeRowIndex and pendingRowIndex (always null without the new model option): a hand-built value of it (a test mock) adds them. ListboxOptionElementProps gains optional aria-posinset, aria-setsize and style, which an option component of yours on useListboxOption receives in a data-mode list (the position) and in a windowed list (its height): spread them, and merge style after your own. DataGridLabels gains resizeColumn and columnWidth.

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) and scrollPaddingStart (the height of a sticky header over the rows, which scrollToIndex places rows below). It returns a VirtualWindow: itemSize, scrollRef (the scrolling element's callback ref), layout(count, { keep }) (the VirtualEntry list to render, { kind: 'item', index } and { kind: 'spacer', size, key }, a pure function called during render; keep holds indexes outside the view, the focused row) and scrollToIndex(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 passive scroll listener read once per animation frame and a ResizeObserver. Pass it to a component's virtualWindow: the component lays the window out itself, since only it knows which item it must keep rendered. Merge scrollRef with your refs or destructure it (ref={virtualWindow.scrollRef} fails the React Compiler's lint). Fluent's closest counterpart is its deprecated Virtualizer; an object of your own that implements VirtualWindow (an adapter over @tanstack/react-virtual, guide) works in every component.
  • DataGrid virtualWindow (virt-1), with items and columns and 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 as scrollPaddingStart); 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 new items make the browser drop focus from a moved row, focus returns to the same row, or the rendered row nearest its place. The grid carries aria-rowcount (the items plus the header rows), every row aria-rowindex (header rows first, body rows in the sorted order) and every body row data-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 virtualWindow and count (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 carry data-index and their place in the whole list (aria-setsize and aria-posinset, or in a grid, navigationMode="composite", aria-rowcount on the list and aria-rowindex on the rows), and spacers are aria-hidden <li>s (<div>s in a grid) with wave-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; when count drops 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, unless navigationMode="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 optionally textValue, disabled and hidden) instead of option children, and renderOption(item, state) (ListboxOptionRenderState: selected, active, index among the shown options; by default an Option with the item's label). The keys, typeahead, the selected labels and the Combobox filter come from items, also for a selected item whose option is not rendered, and every option carries aria-posinset and aria-setsize among the shown options (typing in a Combobox narrows both). A closed data-mode Combobox or Dropdown renders no options (its labels come from items), 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 exactly itemSize tall (the default Option with one line of text is 32 pixels); the active option stays rendered, so aria-activedescendant always 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 a tabIndex of yours wins. A plain windowed List (navigationMode none) keeps the browser's default, under which WebKit does not let the keyboard reach and scroll it: pass tabIndex={0} or navigate its items (navigationMode="items").
  • onScrollToItem(index) on useActiveDescendant and useListbox: called first for every move that scrolls the active item into view (keys, setActiveValue, the fallback that becomes active; never a pointer highlight or a scroll: false move), with the item's index (for useListbox, 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.
  • FlatTree and useFlatTree (tree-9): a tree built from flat data that can render only the items in view. useFlatTree(items, options) takes FlatTreeItemData items (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 a FlatTreeModel: visibleItems (VisibleFlatItem: item, level, position, setSize, parentValue, hasChildren, isBranch, expanded, index, and with selectionMode: 'multiple' checked), getItem, expand (a value or a list, one change), collapse, toggle, isExpanded, setChecked and getTreeProps(). 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 sibling role="treeitem" elements with aria-level, aria-setsize, aria-posinset and aria-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 nested Tree is unchanged.
  • Headless table state (hook-1, hook-2, hook-3): useTableFeatures({ items, columns, getRowId }, plugins) (Fluent's call shape) with the plugin hooks useTableSort (sort, defaultSort, onSortChange(sort, details), DataGrid's DataGridSort shape), useTableSelection (selectionMode, selectedItems, defaultSelectedItems, onSelectedItemsChange(selectedItems, details) with row ids, isDisabled(item, index)) and useTableColumnSizing (below). The state holds getRows() (TableRowData<T>: item, rowId, index, sorted by the sorted column's compare), sort (value, setColumnSort, toggleColumnSort, getSortDirection), selection (selectedItems, allRowsSelected, someRowsSelected over every selectable item, isRowSelected, toggleRow, selectRow, deselectRow, toggleAllRows, clearRows) and columnSizing, each slot inert without its plugin. The state follows the data, not the rendered rows: select-all keeps ids outside items. 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. Types TableFeaturesState, 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) with UseSelectionChangeDetails), returning selectedItems (a ReadonlySet that 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) and clear. Types UseSelectionOptions, UseSelectionResult.
  • Resizable columns (dg-3): DataGrid resizableColumns gives each column's header cell a resize handle (Fluent's name), with columns and items. 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 width defaultWidth, else idealWidth, else 150), columnWidths and defaultColumnWidths (pixels by columnId) and onColumnWidthsChange(widths, details) (every column's width at each step of a drag or key press; TableColumnWidthsChangeDetails: columnId, width, event, Fluent's onColumnResize data). 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 carries data-resizing while a handle drags; labels.resizeColumn ("Resize column") and labels.columnWidth(width) ("N pixels") name and describe the handles.
  • Table.ResizeHandle (TableResizeHandle, TableResizeHandleProps; trh-1), the handle DataGrid renders, for the aside of a positioned Table.HeaderCell: a vertical role="separator" with aria-valuenow, aria-valuemin, aria-valuemax (with maxWidth) and aria-valuetext, taking width, 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") and valueText(width). It is a Tab stop (tabIndex 0) for a static table, keeps no width of its own, carries data-dragging while it drags and data-grid-auxiliary. useTableColumnSizing(options) (hook-4; columnSizingOptions, columnWidths, defaultColumnWidths, onColumnWidthsChange; UseTableColumnSizingOptions) fills columnSizing: columnWidths, isSized, getColumnWidth, setColumnWidth, and the props to spread, getTableProps(), getColumnProps(columnId) (a <col>) and getResizeHandleProps(columnId) (a Table.ResizeHandle, with onReset).
  • useGridNavigation model (GridNavigationModel: rowCount, headerRowCount, scrollToRow(index)) for a grid whose data rows are rendered in part (each rendered row carries data-row-index): the vertical keys move by the data, a target row that is not rendered is asked for with scrollToRow and focused when it renders, and the new results activeRowIndex and pendingRowIndex name the rows to keep rendered. Auxiliary widgets: a widget that carries data-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, VisibleFlatItem and CheckState, and the table-state types above.
  • Stable class names: flatTreeClassNames (root, spacer), flatTreeItemClassNames (root, row, expandIcon, indicator, label) and tableResizeHandleClassNames; new keys spacer on dataGridClassNames, listClassNames, listboxClassNames, comboboxClassNames and dropdownClassNames, and resizeHandle on dataGridHeaderCellClassNames (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 of Listbox, Combobox and Dropdown :items-and-children, :render-option-without-items, :virtual-window-requires-items and :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, ResizableControlled and TenThousandRows; Components/Table/Features (a static Table on the hooks, with Table.ResizeHandle); List Windowed; DataMode and TenThousandOptions on Listbox, Combobox and Dropdown; FlatTree Default, Checkable and FiveThousandNodes.

Changed

Behaviour

  • DataGrid selection with items follows the data ("Upgrading from 0.15", 1 and 2), and the server HTML and first client render of a grid with items show 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-rowindex and data-row-index of a windowed DataGrid, data-index, aria-setsize and aria-posinset on a windowed List's items, aria-posinset and aria-setsize on 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 gets aria-labelledby, so its name stays its label).

Types

  • UseGridNavigationResult gains activeRowIndex and pendingRowIndex, ListboxOptionElementProps gains three optional members and DataGridLabels two ("Upgrading from 0.15", 6); every other change is a new optional prop or a new export.

Development messages

  • DataGrid:single-several-selected names the first given id in a grid with items ("Upgrading from 0.15", 5).

Dev gates

  • verify-dist: an import of only useVirtualWindow stays within VIRTUAL_BUDGET (4,415 bytes minified and 2,048 gzip) and imports nothing but react, and an import of only DataGrid within DATA_GRID_BUDGET (86,990 and 29,431 bytes, 25% over its first 0.16 measurement) and the package's own dependencies; imports of only useVirtualWindow or only useSelection hold no component, one of only DataGrid no FlatTree code, one of only FlatTree no DataGrid code, one of only Tree the moved cascade and no other 0.16 module, and imports of only Button or only MessageBar no 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 with items, 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, and onSelectionChange reports 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: useVirtualWindow with its layout core is 1,817 bytes gzip, under the spec's ceiling of 2 KiB (VIRTUAL_BUDGET gates 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_BUDGET gates 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-dist gates that they hold none of the 0.16 modules.
  • The pickers gain their data mode (Option.data), List its window support, and Table Table.ResizeHandle and the direction helpers it uses.