Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ed023aa
fix: make search/filers/display elements non horizontally scrollable
war-in Sep 18, 2026
e02c560
fix: improve sticky header
war-in Sep 18, 2026
efd392b
fix: remove unused code
war-in Sep 18, 2026
c21f37e
Revert "fix: remove unused code"
war-in Sep 18, 2026
c4b6b03
chore: improve comments
war-in Sep 18, 2026
07a8962
refactor: rename variables
war-in Sep 18, 2026
8591796
refactor: group all header placement-related props into enum
war-in Sep 18, 2026
5333f58
test: adapt test to header-placement changes
war-in Sep 18, 2026
26a55eb
chore: improve comments
war-in Sep 18, 2026
40f189f
chore: revert unnecessary changes
war-in Sep 18, 2026
4a68d32
Merge branch 'main' into war-in/fix-scrollable-table-header-elements
war-in Sep 21, 2026
3ce5e48
chore: stop exporting unused ColumnHeaderPlacement type
war-in Sep 21, 2026
1f1b35b
fix: disable horizontal scroll in list header
war-in Sep 21, 2026
f33ef2c
Merge branch 'refs/heads/main' into war-in/fix-scrollable-table-heade…
war-in Sep 21, 2026
bc0dcdf
fix: return none placement when has rows but header is hidden
war-in Sep 23, 2026
e035a62
fix: dont' override entire `overrideProps`
war-in Sep 23, 2026
cb38c30
fix: add hasRows guard
war-in Sep 23, 2026
d7acecf
chore: improve comments
war-in Sep 23, 2026
693ded6
Merge branch 'main' into war-in/fix-scrollable-table-header-elements
war-in Sep 25, 2026
1020b3e
fix: add `overflowXAuto` style
war-in Sep 25, 2026
6c501cb
fix: match `data-table-column-scroller` on value
war-in Sep 25, 2026
9f2d14b
Merge branch 'main' into war-in/fix-scrollable-table-header-elements
war-in Sep 28, 2026
2e565b8
test: fix missing prop
war-in Sep 28, 2026
96d6ecf
Merge branch 'main' into war-in/fix-scrollable-table-header-elements
war-in Sep 29, 2026
14742d1
refactor: move COLUMN_HEADER_PLACEMENT to consts
war-in Sep 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9136,6 +9136,18 @@ const CONST = {
MULTI_SELECT: 'multiSelect',
},

/** Where the column header is rendered. The placements are exclusive, so the table is always in exactly one of them. */
COLUMN_HEADER_PLACEMENT: {
/** The table has no column header anywhere. */
NONE: 'none',
/** A direct child of the table container, outside the list. Where every table without a page header keeps it. */
OUTSIDE_LIST: 'outsideList',
/** A synthetic list row, which FlashList paints as a sticky overlay outside the scroller. */
STICKY_ROW: 'stickyRow',
/** In flow inside the list header, so the scroller carries it sideways with the columns it labels. */
LIST_HEADER: 'listHeader',
},

DYNAMIC_COLUMNS: {
/** How many of the longest strings are measured per column, since character count only approximates rendered width. */
MEASURED_CANDIDATES_PER_COLUMN: 5,
Expand Down
21 changes: 16 additions & 5 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {TableContextValue} from './TableContext';
import type {TableHeaderProps} from './TableHeader';
import type {TableData, TableHandle, TableMethods, TableProps, TableRow} from './types';

import {getDataVisibleIndices, getListIndex, getTableListMetadata} from './buildTableListData';
import {getDataVisibleIndices, getListIndex, getTableListMetadata, rendersColumnHeader} from './buildTableListData';
import useFiltering from './middlewares/filtering';
import useHighlighting from './middlewares/highlight';
import useSearching from './middlewares/searching';
Expand Down Expand Up @@ -427,16 +427,22 @@ function Table<DataType extends TableData, ColumnKey extends string = string, Fi

return !isTableHeaderElement(child) && !(React.isValidElement(child) && (child.type === TableEmptyState || child.type === TableNoResultsState));
});
const shouldRenderStickyHeader = processedData.length > 0 && !!tableHeaderElement && hasPageHeader && !(shouldUseNarrowTableLayout && !title);
const hasColumnHeaderElement = !!tableHeaderElement;
const hasRows = processedData.length > 0;
const isColumnHeaderHiddenInNarrowLayout = shouldUseNarrowTableLayout && !title;
const areColumnsScrollable = !!dynamicScrollWidth;

const tableListMetadata = useMemo(
() =>
getTableListMetadata({
listHeaderElement,
listHeaderComponent: listProps.ListHeaderComponent,
shouldRenderStickyHeader,
hasColumnHeaderElement,
hasRows,
isColumnHeaderHiddenInNarrowLayout,
areColumnsScrollable,
}),
[listHeaderElement, listProps.ListHeaderComponent, shouldRenderStickyHeader],
[listHeaderElement, listProps.ListHeaderComponent, hasColumnHeaderElement, hasRows, isColumnHeaderHiddenInNarrowLayout, areColumnsScrollable],
);
/**
* Exposes table control methods through the ref.
Expand Down Expand Up @@ -503,6 +509,8 @@ function Table<DataType extends TableData, ColumnKey extends string = string, Fi
originalDataLength,
columns,
dynamicGridTemplateColumns,
scrollWidth: dynamicScrollWidth,
tableWidth,
filterConfig: filters,
activeFilters: currentFilters,
activeSorting,
Expand Down Expand Up @@ -543,7 +551,10 @@ function Table<DataType extends TableData, ColumnKey extends string = string, Fi
columnCount={semanticColumnCount}
rendersBodyWhenEmpty={rendersBodyWhenEmpty}
shouldUseDynamicColumns={shouldUseDynamicColumns}
scrollWidth={dynamicScrollWidth}
hasHeaderRow={rendersColumnHeader(tableListMetadata)}
// Only tables without a page header scroll here. With one, an ancestor scroller would drag the
// in-list filter bar sideways, so their list scrolls horizontally itself (see `TableBody`).
scrollWidth={hasPageHeader ? undefined : dynamicScrollWidth}
onLayout={isDynamicSizingEnabled ? handleTableLayout : undefined}
>
{renderedChildren}
Expand Down
99 changes: 89 additions & 10 deletions src/components/Table/TableBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import useBottomSafeSafeAreaPaddingStyle from '@hooks/useBottomSafeSafeAreaPaddi
import useDebouncedAccessibilityAnnouncement from '@hooks/useDebouncedAccessibilityAnnouncement';
import useLocalize from '@hooks/useLocalize';
import useScrollEnabled from '@hooks/useScrollEnabled';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';

import type {ListRenderItemInfo, ViewToken} from '@shopify/flash-list';
Expand All @@ -17,7 +18,16 @@ import {StyleSheet, View} from 'react-native';
import type {TableData} from '.';
import type {TableListMetadata} from './buildTableListData';

import {buildTableListData, getAdjustedStickyHeaderIndices, getDataIndex, getListIndex, getSyntheticRowKind} from './buildTableListData';
import {
buildTableListData,
getAdjustedStickyHeaderIndices,
getDataIndex,
getListIndex,
getSyntheticRowKind,
rendersColumnHeader,
rendersColumnHeaderAsStickyRow,
rendersColumnHeaderInListHeader,
} from './buildTableListData';
import {getRowGroupAccessibilityProps, getTableContainerAccessibilityProps, getVirtualizedRowSemanticID, shouldUseTableSemantics} from './tableAccessibility';
import {TableRowSemanticIDContext, useTableContext} from './TableContext';

Expand All @@ -34,6 +44,37 @@ type TableBodyListProps = TableBodyProps & {
emptyMessage: string;
};

type ColumnScrollOverrideProps = Record<string, unknown> & {
dataSet?: Record<string, unknown>;
style?: StyleProp<ViewStyle>;
};

/**
* Hands the horizontal axis to the list's scroller and marks it for the page-header hover rule in `web/index.html`,
* keeping whatever `overrideProps` the consumer passed.
*/
function getColumnScrollOverrideProps(overflowXAutoStyle: ViewStyle, overrideProps: ColumnScrollOverrideProps = {}) {
return {
...overrideProps,
dataSet: {...overrideProps.dataSet, tableColumnScroller: true},
style: [overrideProps.style, overflowXAutoStyle],
};
}

/**
* Pins the page header to the scroller's left edge so it stays put while the columns move under it. Held at the
* measured table width: a box spanning the scroll range has nothing to pin within, and a percentage resolves to it.
*/
const columnScrollPageHeaderStyle = {position: 'sticky', left: 0} as ViewStyle;

/**
* Sticks the shared list-header box at minus the page header's height, so exactly that much scrolls off and leaves the
* column header flush against the scroller. `zIndex` lifts it above the rows, which paint later in tree order.
*/
function getColumnScrollListHeaderStyle(pageHeaderHeight: number): ViewStyle {
return {position: 'sticky', top: -pageHeaderHeight, zIndex: 1} as ViewStyle;
}

type ViewabilityInfo = {
viewableItems: Array<ViewToken<TableData>>;
changed: Array<ViewToken<TableData>>;
Expand Down Expand Up @@ -97,10 +138,13 @@ function doesBodyRenderWhenEmpty(listProps: {ListEmptyComponent?: unknown; ListH
*/
function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ...props}: TableBodyListProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const scrollEnabled = useScrollEnabled();
const [isListLoaded, setIsListLoaded] = useState(false);
const [hasActivatedStickyHeader, setHasActivatedStickyHeader] = useState(false);
const [activeStickyHeaderIndex, setActiveStickyHeaderIndex] = useState(-1);
// The page header is consumer content, so its height is only known after layout. `0` keeps the list header unstuck.
const [pageHeaderHeight, setPageHeaderHeight] = useState(0);
const {
processedData: filteredAndSortedData,
listProps,
Expand All @@ -117,13 +161,16 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
noResultsStateElement,
tableListMetadata,
isEmptyResult,
scrollWidth,
tableWidth,
} = useTableContext<TableData>();
const {
ListEmptyComponent,
ListEmptyComponentStyle,
ListFooterComponent,
ListFooterComponentStyle,
ListHeaderComponent,
ListHeaderComponentStyle,
contentContainerStyle: listContentContainerStyle,
getItemType,
initialScrollIndex,
Expand All @@ -135,6 +182,7 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
onStartReached,
onViewableItemsChanged,
overrideItemLayout,
overrideProps,
renderItem,
stickyHeaderIndices,
viewabilityConfigCallbackPairs,
Expand All @@ -153,21 +201,27 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
const contentMinHeight = flattenedContentContainerStyle?.minHeight;
const {paddingBottom: tableBodyBottomPadding} = StyleSheet.flatten(tableBodyContentContainerStyle) ?? {};

const shouldRenderStickyHeader = tableListMetadata.shouldRenderStickyHeader;
const shouldRenderColumnHeaderAsStickyRow = rendersColumnHeaderAsStickyRow(tableListMetadata);
const shouldRenderColumnHeaderInListHeader = rendersColumnHeaderInListHeader(tableListMetadata);
const hasRows = filteredAndSortedData.length > 0;
const shouldRenderFlashList = hasRows || (tableListMetadata.hasPageHeader && isEmptyResult);

// Columns wider than the table, so this list's scroller takes the horizontal axis (see `getColumnScrollOverrideProps`).
// Only tables keeping their filter bar in the list scroll here. The rest are scrolled by an ancestor (see
// `TableSemanticContainer`). Web-only: native can't measure text, so it never content-sizes columns.
const isColumnScrollEnabled = !!scrollWidth && tableListMetadata.hasPageHeader && hasRows;
const isTableSemanticsEnabled = shouldUseTableSemantics(shouldUseNarrowTableLayout);
const shouldApplyPageHeaderTable = isTableSemanticsEnabled && tableListMetadata.hasPageHeader && hasRows;
const shouldApplyBodyRowGroup = isTableSemanticsEnabled && !tableListMetadata.hasPageHeader;
const semanticTableHasHeader = !tableListMetadata.hasPageHeader || tableListMetadata.shouldRenderStickyHeader;
const semanticTableHasHeader = rendersColumnHeader(tableListMetadata);
const semanticColumnCount = columns.length + (selectionEnabled ? 1 : 0);
const tableBodyAccessibilityProps = tableListMetadata.hasPageHeader
? getTableContainerAccessibilityProps(shouldApplyPageHeaderTable, title, filteredAndSortedData.length, semanticColumnCount, semanticTableHasHeader)
: getRowGroupAccessibilityProps(shouldApplyBodyRowGroup);
const currentListState = {shouldRenderFlashList, shouldRenderStickyHeader};
const currentListState = {shouldRenderFlashList, shouldRenderColumnHeaderAsStickyRow};
const [previousListState, setPreviousListState] = useState(currentListState);
const shouldResetListLoad = previousListState.shouldRenderFlashList !== shouldRenderFlashList;
const shouldResetStickyHeader = previousListState.shouldRenderStickyHeader !== shouldRenderStickyHeader;
const shouldResetStickyHeader = previousListState.shouldRenderColumnHeaderAsStickyRow !== shouldRenderColumnHeaderAsStickyRow;

if (shouldResetListLoad || shouldResetStickyHeader) {
setPreviousListState(currentListState);
Expand All @@ -183,13 +237,13 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
}

useEffect(() => {
if (!hasRows || !tableListMetadata.shouldRenderStickyHeader || !isListLoaded || hasActivatedStickyHeader) {
if (!hasRows || !shouldRenderColumnHeaderAsStickyRow || !isListLoaded || hasActivatedStickyHeader) {
return;
}

const frame = requestAnimationFrame(() => setHasActivatedStickyHeader(true));
return () => cancelAnimationFrame(frame);
}, [hasActivatedStickyHeader, hasRows, isListLoaded, tableListMetadata.shouldRenderStickyHeader]);
}, [hasActivatedStickyHeader, hasRows, isListLoaded, shouldRenderColumnHeaderAsStickyRow]);

const handleChangeStickyIndex: NonNullable<typeof onChangeStickyIndex> = useCallback(
(current, previous) => {
Expand Down Expand Up @@ -239,12 +293,29 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
};

const pageHeaderElement = tableListMetadata.hasPageHeader ? (
<View>
<View
style={isColumnScrollEnabled && [columnScrollPageHeaderStyle, tableWidth > 0 && StyleUtils.getWidthStyle(tableWidth)]}
// Measured unconditionally, so the height is known by the time the columns overflow and need it.
onLayout={(event) => setPageHeaderHeight(event.nativeEvent.layout.height)}
// Pairs with the scroller's marker so a stylesheet rule can suspend the columns on hover (see `web/index.html`).
dataSet={{tablePageHeader: true}}
>
{renderListComponent(ListHeaderComponent)}
{listHeaderElement}
</View>
) : null;

// While the columns scroll the column header sits here rather than in FlashList's sticky-row overlay, so the
// scroller carries it sideways. Also one copy instead of the overlay's two, so no duplicate to hide from readers.
const listHeaderContent = shouldRenderColumnHeaderInListHeader ? (
<>
{pageHeaderElement}
{tableHeaderElement}
</>
) : (
pageHeaderElement
);

const EmptyResultComponent = (
<View style={[styles.ph5, styles.pt3, styles.pb5]}>
<Text
Expand Down Expand Up @@ -310,7 +381,7 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
// A truly empty table still uses the standalone centered layout above.
const listData = buildTableListData<TableData>(filteredAndSortedData, tableListMetadata);
const adjustedStickyHeaderIndices = getAdjustedStickyHeaderIndices(tableListMetadata, stickyHeaderIndices);
const canRenderStickyHeader = !tableListMetadata.shouldRenderStickyHeader || (isListLoaded && hasActivatedStickyHeader);
const canRenderStickyHeader = !shouldRenderColumnHeaderAsStickyRow || (isListLoaded && hasActivatedStickyHeader);
const isTableHeaderSticky = activeStickyHeaderIndex === tableListMetadata.stickyTableHeaderIndex;
const shouldRenderEmptyStateInList = !hasRows && tableListMetadata.hasPageHeader;

Expand Down Expand Up @@ -387,7 +458,12 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
style={[styles.flex1, styles.mnh0]}
showsVerticalScrollIndicator={false}
maintainVisibleContentPosition={{disabled: true}}
ListHeaderComponent={pageHeaderElement}
ListHeaderComponent={listHeaderContent}
ListHeaderComponentStyle={[
ListHeaderComponentStyle,
// An unmeasured page header leaves nothing to offset the stack by, and 0 would pin it instead.
pageHeaderHeight > 0 && shouldRenderColumnHeaderInListHeader && getColumnScrollListHeaderStyle(pageHeaderHeight),
]}
ListEmptyComponent={shouldRenderEmptyStateInList ? emptyStateContent : ListEmptyComponent}
ListEmptyComponentStyle={[ListEmptyComponentStyle, shouldRenderEmptyStateInList && styles.flexGrow1, shouldRenderEmptyStateInList && styles.justifyContentCenter]}
ListFooterComponent={ListFooterComponent}
Expand All @@ -399,6 +475,8 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
listContentContainerStyle,
tableBodyContentContainerStyle,
contentContainerStyle,
// Absolutely positioned rows don't widen the scroller's content, so hold the scroll extent open.
isColumnScrollEnabled && StyleUtils.getMinimumWidth(scrollWidth),
shouldRenderEmptyStateInList && styles.flexGrow1,
shouldUseNarrowTableLayout &&
typeof contentMinHeight === 'number' &&
Expand All @@ -422,6 +500,7 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
}}
{...restListProps}
scrollEnabled={scrollEnabled}
overrideProps={isColumnScrollEnabled ? getColumnScrollOverrideProps(styles.overflowXAuto, overrideProps) : overrideProps}
/>
</View>
);
Expand Down
10 changes: 9 additions & 1 deletion src/components/Table/TableContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ type TableContextValue<DataType extends TableData, ColumnKey extends string = st
*/
dynamicGridTemplateColumns: string[] | undefined;

/** The width the rows need when the columns don't fit, which makes the list scroll horizontally too. `undefined` means they fit. */
scrollWidth: number | undefined;

/** Measured width of the area the table lays out into. Content-sized columns only. `0` until the first layout. */
tableWidth: number;

/** Filter configuration for dropdown filters. */
filterConfig: FilterConfig<FilterKey> | undefined;

Expand Down Expand Up @@ -132,6 +138,8 @@ const defaultTableContextValue: TableContextValue<TableData, string> = {
originalDataLength: 0,
columns: [],
dynamicGridTemplateColumns: undefined,
scrollWidth: undefined,
tableWidth: 0,
activeFilters: {},
activeSorting: {
columnKey: undefined,
Expand All @@ -148,7 +156,7 @@ const defaultTableContextValue: TableContextValue<TableData, string> = {
hasSearchString: false,
tableListMetadata: {
hasPageHeader: false,
shouldRenderStickyHeader: false,
columnHeaderPlacement: CONST.TABLES.COLUMN_HEADER_PLACEMENT.NONE,
syntheticRowsBeforeData: 0,
stickyTableHeaderIndex: 0,
listDataRowOffset: 0,
Expand Down
Loading
Loading