diff --git a/apps/vr-tests-react-components/src/stories/Table.stories.tsx b/apps/vr-tests-react-components/src/stories/Table.stories.tsx
index a4141467d2a5e1..17d5238e7e2c9e 100644
--- a/apps/vr-tests-react-components/src/stories/Table.stories.tsx
+++ b/apps/vr-tests-react-components/src/stories/Table.stories.tsx
@@ -23,12 +23,43 @@ import {
TableCellActions,
TableProps,
TableRowProps,
+ useTableColumnSizing_unstable,
+ useTableFeatures,
+ TableColumnDefinition,
+ createTableColumn,
} from '@fluentui/react-table';
import { Button } from '@fluentui/react-button';
import { storiesOf } from '@storybook/react';
import { Steps, StoryWright } from 'storywright';
-const items = [
+type FileCell = {
+ label: string;
+ icon: JSX.Element;
+};
+
+type LastUpdatedCell = {
+ label: string;
+ timestamp: number;
+};
+
+type LastUpdateCell = {
+ label: string;
+ icon: JSX.Element;
+};
+
+type AuthorCell = {
+ label: string;
+ status: PresenceBadgeStatus;
+};
+
+type Item = {
+ file: FileCell;
+ author: AuthorCell;
+ lastUpdated: LastUpdatedCell;
+ lastUpdate: LastUpdateCell;
+};
+
+const items: Item[] = [
{
file: { label: 'Meeting notes', icon: },
author: { label: 'Max Mustermann', status: 'available' },
@@ -74,6 +105,25 @@ const columns = [
{ columnKey: 'lastUpdate', label: 'Last update' },
];
+const columnsDef: TableColumnDefinition- [] = [
+ createTableColumn
- ({
+ columnId: 'file',
+ renderHeaderCell: () => <>File>,
+ }),
+ createTableColumn
- ({
+ columnId: 'author',
+ renderHeaderCell: () => <>Author>,
+ }),
+ createTableColumn
- ({
+ columnId: 'lastUpdated',
+ renderHeaderCell: () => <>Last updated>,
+ }),
+ createTableColumn
- ({
+ columnId: 'lastUpdate',
+ renderHeaderCell: () => <>Last update>,
+ }),
+];
+
interface SharedVrTestArgs {
noNativeElements: TableProps['noNativeElements'];
selectedRowAppearance?: TableRowProps['appearance'];
@@ -634,6 +684,85 @@ const Truncate: React.FC = ({ noNativ
);
+const ResizableColumns: React.FC = ({
+ noNativeElements,
+ scrollToEnd,
+}) => {
+ const [columnSizingOptions] = React.useState({
+ file: {
+ idealWidth: 300,
+ minWidth: 300,
+ },
+ });
+
+ const { columnSizing_unstable: columnSizing, tableRef } = useTableFeatures(
+ {
+ columns: columnsDef,
+ items,
+ },
+ [
+ useTableColumnSizing_unstable({
+ columnSizingOptions,
+ }),
+ ],
+ );
+ return (
+
+
+
+
+ {columns.map(column => (
+
+ {column.label}
+
+ ))}
+
+
+
+ {items.map((item, i) => (
+
+
+
+ {item.file.label}
+
+ } appearance="subtle" />
+ } appearance="subtle" />
+
+
+
+
+
+ }
+ >
+ {item.author.label}
+
+
+
+ {item.lastUpdated.label}
+
+
+
+ {item.lastUpdate.label}
+
+
+ {
+ if (el && scrollToEnd) {
+ el.scrollIntoView();
+ }
+ }}
+ />
+
+ ))}
+
+
+
+ );
+};
+
([true, false] as const).forEach(noNativeElements => {
const layoutName = noNativeElements ? 'flex' : 'table';
storiesOf(`Table layout ${layoutName} - cell actions`, module)
@@ -760,4 +889,8 @@ const Truncate: React.FC = ({ noNativ
.addStory('default (disabled)', () => )
.addStory('false', () => )
.addStory('true', () => );
+
+ storiesOf(`Table layout ${layoutName} - resizable columns`, module)
+ .addStory('default', () => )
+ .addStory('end', () => );
});
diff --git a/change/@fluentui-react-table-1a06bc91-0c0f-464f-a1c3-4523427d45a1.json b/change/@fluentui-react-table-1a06bc91-0c0f-464f-a1c3-4523427d45a1.json
new file mode 100644
index 00000000000000..e5b367f414a594
--- /dev/null
+++ b/change/@fluentui-react-table-1a06bc91-0c0f-464f-a1c3-4523427d45a1.json
@@ -0,0 +1,7 @@
+{
+ "type": "patch",
+ "comment": "fix: Improve visuals when Table/DataGrid overflows it's parent",
+ "packageName": "@fluentui/react-table",
+ "email": "jirivyhnalek@microsoft.com",
+ "dependentChangeType": "patch"
+}
diff --git a/packages/react-components/react-table/src/components/DataGrid/useDataGrid.ts b/packages/react-components/react-table/src/components/DataGrid/useDataGrid.ts
index 039d058be6bacd..acf991ca4359f6 100644
--- a/packages/react-components/react-table/src/components/DataGrid/useDataGrid.ts
+++ b/packages/react-components/react-table/src/components/DataGrid/useDataGrid.ts
@@ -112,6 +112,7 @@ export const useDataGrid_unstable = (props: DataGridProps, ref: React.Ref;
export type ColumnSizingTableHeaderCellProps = Pick;
export type ColumnSizingTableCellProps = Pick;
@@ -184,6 +185,7 @@ export interface TableColumnSizingState {
getOnMouseDown: (columnId: TableColumnId) => (e: React.MouseEvent | React.TouchEvent) => void;
setColumnWidth: (columnId: TableColumnId, newSize: number) => void;
getColumnWidths: () => ColumnWidthState[];
+ getTableProps: (props?: Partial) => ColumnSizingTableProps;
getTableHeaderCellProps: (columnId: TableColumnId) => ColumnSizingTableHeaderCellProps;
getTableCellProps: (columnId: TableColumnId) => ColumnSizingTableCellProps;
enableKeyboardMode: (
diff --git a/packages/react-components/react-table/src/hooks/useTableColumnSizing.test.ts b/packages/react-components/react-table/src/hooks/useTableColumnSizing.test.ts
index 66502b4399c78c..7f3669171bce08 100644
--- a/packages/react-components/react-table/src/hooks/useTableColumnSizing.test.ts
+++ b/packages/react-components/react-table/src/hooks/useTableColumnSizing.test.ts
@@ -62,6 +62,7 @@ describe('useTableColumnSizing', () => {
"getOnMouseDown": [MockFunction],
"getTableCellProps": [Function],
"getTableHeaderCellProps": [Function],
+ "getTableProps": [Function],
"setColumnWidth": [Function],
}
`);
diff --git a/packages/react-components/react-table/src/hooks/useTableColumnSizing.tsx b/packages/react-components/react-table/src/hooks/useTableColumnSizing.tsx
index 2c1a3cfe3e120c..1f63ef74d398ed 100644
--- a/packages/react-components/react-table/src/hooks/useTableColumnSizing.tsx
+++ b/packages/react-components/react-table/src/hooks/useTableColumnSizing.tsx
@@ -18,6 +18,7 @@ export const defaultColumnSizingState: TableColumnSizingState = {
getColumnWidths: () => [],
getOnMouseDown: () => () => null,
setColumnWidth: () => null,
+ getTableProps: () => ({}),
getTableHeaderCellProps: () => ({ style: {}, columnId: '' }),
getTableCellProps: () => ({ style: {}, columnId: '' }),
enableKeyboardMode: () => () => null,
@@ -75,16 +76,27 @@ function useTableColumnSizingState(
setColumnWidth: (columnId: TableColumnId, w: number) =>
columnResizeState.setColumnWidth(undefined, { columnId, width: w }),
getColumnWidths: columnResizeState.getColumns,
+ getTableProps: (props = {}) => {
+ return {
+ ...props,
+ style: {
+ minWidth: 'fit-content',
+ ...(props.style || {}),
+ },
+ };
+ },
getTableHeaderCellProps: (columnId: TableColumnId) => {
const col = columnResizeState.getColumnById(columnId);
+ const isLastColumn = columns[columns.length - 1]?.columnId === columnId;
- const aside = (
+ const aside = isLastColumn ? null : (
);
+
return col
? {
style: getColumnStyles(col),
diff --git a/packages/react-components/react-table/stories/DataGrid/ResizableColumns.stories.tsx b/packages/react-components/react-table/stories/DataGrid/ResizableColumns.stories.tsx
index 94df950d89f9b9..a9c0f19313329c 100644
--- a/packages/react-components/react-table/stories/DataGrid/ResizableColumns.stories.tsx
+++ b/packages/react-components/react-table/stories/DataGrid/ResizableColumns.stories.tsx
@@ -178,47 +178,49 @@ export const ResizableColumns = () => {
const refMap = React.useRef>({});
return (
- item.file.label}
- selectionMode="multiselect"
- resizableColumns
- columnSizingOptions={columnSizingOptions}
- >
-
-
- {({ renderHeaderCell, columnId }, dataGrid) =>
- dataGrid.resizableColumns ? (
-
- ) : (
- {renderHeaderCell()}
- )
- }
-
-
- >
- {({ item, rowId }) => (
- key={rowId} selectionCell={{ 'aria-label': 'Select row' }}>
- {({ renderCell }) => {renderCell(item)}}
+
+ item.file.label}
+ selectionMode="multiselect"
+ resizableColumns
+ columnSizingOptions={columnSizingOptions}
+ >
+
+
+ {({ renderHeaderCell, columnId }, dataGrid) =>
+ dataGrid.resizableColumns ? (
+
+ ) : (
+ {renderHeaderCell()}
+ )
+ }
- )}
-
-
+
+ >
+ {({ item, rowId }) => (
+ key={rowId} selectionCell={{ 'aria-label': 'Select row' }}>
+ {({ renderCell }) => {renderCell(item)}}
+
+ )}
+
+
+
);
};
diff --git a/packages/react-components/react-table/stories/Table/ResizableColumnsControlled.stories.tsx b/packages/react-components/react-table/stories/Table/ResizableColumnsControlled.stories.tsx
index 7661bd6657680f..5fda7f533f0628 100644
--- a/packages/react-components/react-table/stories/Table/ResizableColumnsControlled.stories.tsx
+++ b/packages/react-components/react-table/stories/Table/ResizableColumnsControlled.stories.tsx
@@ -272,46 +272,48 @@ export const ResizableColumnsControlled = () => {
Add removed column
-
-
-
- {columns.map((column, index) => (
-
- ))}
-
-
-
- {rows.map(({ item }) => (
-
- {columns.map(column => (
-
- {column.renderCell(item)}
-
+
+
+
+
+ {columns.map((column, index) => (
+
))}
- ))}
-
-
+
+
+ {rows.map(({ item }) => (
+
+ {columns.map(column => (
+
+ {column.renderCell(item)}
+
+ ))}
+
+ ))}
+
+
+
>
);
};
diff --git a/packages/react-components/react-table/stories/Table/ResizableColumnsUncontrolled.stories.tsx b/packages/react-components/react-table/stories/Table/ResizableColumnsUncontrolled.stories.tsx
index db34111c955683..03416a45201829 100644
--- a/packages/react-components/react-table/stories/Table/ResizableColumnsUncontrolled.stories.tsx
+++ b/packages/react-components/react-table/stories/Table/ResizableColumnsUncontrolled.stories.tsx
@@ -161,60 +161,62 @@ export const ResizableColumnsUncontrolled = () => {
-
-
-
- {columns.map(column => (
-
+
>
);
};