@dooherceg/material-react-table 4.0.3 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -2294,7 +2294,39 @@ const MRT_ExpandButton = ({
2294
2294
  const canExpand = row.getCanExpand() && (maxDepth === undefined || row.depth < maxDepth - 1);
2295
2295
  const handleToggleExpand = event => {
2296
2296
  event.stopPropagation();
2297
- row.toggleExpanded();
2297
+ // row.toggleExpanded() is never called here. Its internal read of
2298
+ // row.table.atoms.expanded.get() can go stale relative to the live
2299
+ // table.getState() after repeated toggles on the same row (observed: a row's
2300
+ // second collapse silently no-ops - state and UI both stay exactly as they
2301
+ // were, with no error). table.getState()/table.setExpanded() stayed reliable
2302
+ // through the same repeated-toggle sequence, so the resulting map is always
2303
+ // built from those directly instead.
2304
+ const currentExpanded = table.getState().expanded;
2305
+ const isCurrentlyExpanded = currentExpanded === true || !!currentExpanded[row.id];
2306
+ if (isCurrentlyExpanded) {
2307
+ if (currentExpanded === true) {
2308
+ const next = {};
2309
+ Object.values(table.getRowModel().rowsById).forEach(otherRow => {
2310
+ if (otherRow.id !== row.id && otherRow.getCanExpand()) {
2311
+ next[otherRow.id] = true;
2312
+ }
2313
+ });
2314
+ table.setExpanded(next);
2315
+ } else {
2316
+ const next_0 = {
2317
+ ...currentExpanded
2318
+ };
2319
+ delete next_0[row.id];
2320
+ table.setExpanded(next_0);
2321
+ }
2322
+ } else {
2323
+ // isCurrentlyExpanded is false, so currentExpanded can't be `true` here.
2324
+ const next_1 = {
2325
+ ...currentExpanded
2326
+ };
2327
+ next_1[row.id] = true;
2328
+ table.setExpanded(next_1);
2329
+ }
2298
2330
  iconButtonProps?.onClick?.(event);
2299
2331
  };
2300
2332
  const detailPanel = !!renderDetailPanel?.({