Skip to content

Commit c2deb1a

Browse files
authored
Merge pull request #733 from icflorescu/next
Improve column resizing management and performance, update deps & changelog
2 parents b63bbd0 + f8b978a commit c2deb1a

16 files changed

+415
-77
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
The following is a list of notable changes to the Mantine DataTable component.
44
Minor versions that are not listed in the changelog are bug fixes and small improvements.
55

6+
## 8.1.3 (2025-07-21)
7+
8+
- Enhance column resizing behavior for closed columns - many thanks to [Giovambattista Fazioli](https://github.com/gfazioli) for PR [#711](https://github.com/icflorescu/mantine-datatable/pull/711)
9+
610
## 8.1.2 (2025-03-24)
711

812
- Use `ref` prop instead of `forwardRef`, which was deprecated in React 19

app/examples/column-resizing/ResizingExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function ResizingExample() {
1414
const { effectiveColumns, resetColumnsWidth } = useDataTableColumns<Company>({
1515
key,
1616
columns: [
17-
{ accessor: 'name', width: 100, resizable: true },
17+
{ accessor: 'name', width: 200, resizable: true },
1818
{ accessor: 'streetAddress', resizable: true },
1919
{ accessor: 'city', ellipsis: true, resizable: true },
2020
{ accessor: 'state', textAlign: 'right' },

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mantine-datatable",
3-
"version": "8.1.2",
3+
"version": "8.1.3",
44
"description": "The lightweight, dependency-free, dark-theme aware table component for your Mantine UI data-rich applications, featuring asynchronous data loading support, pagination, intuitive Gmail-style additive batch rows selection, column sorting, custom cell data rendering, row expansion, nesting, context menus, and much more",
55
"keywords": [
66
"mantine",

package/DataTable.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
border: rem(1px) solid var(--mantine-datatable-border-color);
4949
}
5050

51+
.mantine-datatable-resizable-columns {
52+
table-layout: fixed;
53+
}
54+
55+
.mantine-datatable-resizable-columns th {
56+
overflow: hidden;
57+
text-overflow: ellipsis;
58+
white-space: nowrap;
59+
}
60+
5161
.mantine-datatable-table {
5262
border-collapse: separate;
5363
border-spacing: 0;

package/DataTable.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ export function DataTable<T>({
141141
return groups?.flatMap((group) => group.columns) ?? columns!;
142142
}, [columns, groups]);
143143

144+
const hasResizableColumns = useMemo(() => {
145+
return effectiveColumns.some((col) => col.resizable);
146+
}, [effectiveColumns]);
147+
144148
const dragToggle = useDataTableColumns({
145149
key: storeColumnsKey,
146150
columns: effectiveColumns,
@@ -335,6 +339,7 @@ export function DataTable<T>({
335339
'mantine-datatable-selection-column-visible': selectionColumnVisible,
336340
'mantine-datatable-pin-first-column': pinFirstColumn,
337341
'mantine-datatable-pin-first-column-scrolled': !scrolledToLeft && pinFirstColumn,
342+
'mantine-datatable-resizable-columns': hasResizableColumns,
338343
},
339344
classNames?.table
340345
)}

package/DataTableColumns.context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface DataTableColumnsContext {
2222
resetColumnsToggle: () => void;
2323

2424
setColumnWidth: (accessor: string, width: string | number) => void;
25+
setMultipleColumnWidths: (updates: Array<{ accessor: string; width: string | number }>) => void;
2526
resetColumnsWidth: () => void;
2627
}
2728

package/DataTableDragToggleProvider.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type DataTableColumnsProviderProps = PropsWithChildren<{
1414
resetColumnsToggle: () => void;
1515

1616
setColumnWidth: (accessor: string, width: string | number) => void;
17+
setMultipleColumnWidths: (updates: Array<{ accessor: string; width: string | number }>) => void;
1718
resetColumnsWidth: () => void;
1819
}>;
1920

@@ -29,6 +30,7 @@ export const DataTableColumnsProvider = (props: DataTableColumnsProviderProps) =
2930
resetColumnsToggle,
3031

3132
setColumnWidth,
33+
setMultipleColumnWidths,
3234
resetColumnsWidth,
3335
} = props;
3436

@@ -66,6 +68,7 @@ export const DataTableColumnsProvider = (props: DataTableColumnsProviderProps) =
6668
resetColumnsToggle,
6769

6870
setColumnWidth,
71+
setMultipleColumnWidths,
6972
resetColumnsWidth,
7073
}}
7174
>

package/DataTableHeaderCell.css

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,63 @@
4646

4747
.mantine-datatable-header-resizable-handle {
4848
position: absolute;
49-
cursor: 'col-resize';
49+
cursor: col-resize;
5050
top: 0;
5151
bottom: 0;
52-
width: rem(8px);
53-
background: inherit;
54-
cursor: col-resize;
55-
z-index: 1;
56-
transform: translateX(50%);
52+
right: -6px; /* Extend further to the right */
53+
width: 12px; /* Wider for easier clicking */
54+
background: transparent;
55+
z-index: 100; /* Higher z-index to ensure it's above other elements */
5756
opacity: 0;
5857
transition: opacity 0.2s;
58+
5959
&::after {
6060
position: absolute;
6161
content: '';
62-
top: rem(1px);
63-
bottom: rem(1px);
64-
left: rem(2px);
65-
border-right: rem(4px) dotted light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4));
62+
top: 2px;
63+
bottom: 2px;
64+
left: 5px; /* Centered in the wider handle */
65+
width: 2px;
66+
background: light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4));
67+
border-radius: 1px;
68+
transition: background-color 0.2s;
6669
}
67-
&:hover::after {
68-
border-color: var(--mantine-primary-color-6);
70+
71+
&:hover {
72+
opacity: 1;
73+
&::after {
74+
background: var(--mantine-primary-color-6);
75+
}
76+
}
77+
78+
&:active {
79+
opacity: 1 !important;
80+
&::after {
81+
background: var(--mantine-primary-color-7);
82+
}
6983
}
7084
}
7185

7286
tr:hover .mantine-datatable-header-resizable-handle {
7387
opacity: 1;
7488
}
7589

90+
/* Ensure resize handle is always visible and accessible for columns with toggleable buttons */
91+
.mantine-datatable-header-cell-toggleable.mantine-datatable-header-cell-resizable:hover .mantine-datatable-header-resizable-handle {
92+
opacity: 1;
93+
}
94+
95+
/* Enhanced visual feedback during resizing */
96+
.mantine-datatable-header-cell-resizable:has(.mantine-datatable-header-resizable-handle:active) {
97+
background: light-dark(var(--mantine-color-blue-0), var(--mantine-color-dark-7));
98+
transition: background 0.1s;
99+
}
100+
101+
.mantine-datatable-header-cell-resizable:has(.mantine-datatable-header-resizable-handle:active) + th {
102+
background: light-dark(var(--mantine-color-blue-0), var(--mantine-color-dark-7));
103+
transition: background 0.1s;
104+
}
105+
76106
.mantine-datatable-header-cell-sortable-group {
77107
gap: 0.25em;
78108
}

package/DataTableHeaderCell.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export function DataTableHeaderCell<T>({
125125

126126
return (
127127
<TableTh
128+
data-accessor={accessor}
128129
className={clsx(
129130
{
130131
'mantine-datatable-header-cell-sortable': sortable,
@@ -231,7 +232,9 @@ export function DataTableHeaderCell<T>({
231232
</DataTableHeaderCellFilter>
232233
) : null}
233234
</Group>
234-
{resizable ? <DataTableResizableHeaderHandle accessor={accessor as string} columnRef={columnRef} /> : null}
235+
{resizable && accessor !== '__selection__' ? (
236+
<DataTableResizableHeaderHandle accessor={accessor as string} columnRef={columnRef} />
237+
) : null}
235238
</TableTh>
236239
);
237240
}

package/DataTableHeaderSelectorCell.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
.mantine-datatable-header-selector-cell {
22
position: sticky;
33
z-index: 1;
4-
width: 0;
4+
width: 44px;
5+
min-width: 44px;
6+
max-width: 44px;
57
left: 0;
8+
text-align: center;
9+
padding: var(--mantine-spacing-xs);
610
&::after {
711
content: '';
812
position: absolute;

0 commit comments

Comments
 (0)