@linzjs/step-ag-grid 32.3.0 → 32.4.0
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/step-ag-grid.cjs +26 -5
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +26 -5
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +5 -1
- package/src/components/gridPopoverEdit/GridButton.tsx +3 -1
- package/src/components/gridPopoverEdit/GridEditBoolean.tsx +5 -1
- package/src/contexts/GridContextProvider.tsx +15 -7
- package/src/stories/grid/GridPopoutEditBoolean.stories.tsx +9 -8
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
ValueFormatterParams,
|
|
29
29
|
} from 'ag-grid-community';
|
|
30
30
|
import { AgGridReact } from 'ag-grid-react';
|
|
31
|
+
import isChromatic from 'chromatic/isChromatic';
|
|
31
32
|
import clsx from 'clsx';
|
|
32
33
|
import { defer, delay, difference, isEmpty, last, omit, xorBy } from 'lodash-es';
|
|
33
34
|
import { ReactElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -487,6 +488,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
487
488
|
'GridCell-readonly': (ccp: CellClassParams<TData>) =>
|
|
488
489
|
!suppressReadOnlyStyle && !editable(ccp as unknown as EditableCallbackParams<TData>),
|
|
489
490
|
},
|
|
491
|
+
width: colDef.minWidth || 120,
|
|
490
492
|
};
|
|
491
493
|
}
|
|
492
494
|
},
|
|
@@ -1083,7 +1085,9 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
1083
1085
|
const onGridSizeChanged = useCallback(
|
|
1084
1086
|
(event: GridSizeChangedEvent<TData>) => {
|
|
1085
1087
|
if (sizeColumns === 'fit' || (['auto', 'auto-skip-headers'].includes(sizeColumns) && hasSetContentSize.current)) {
|
|
1086
|
-
|
|
1088
|
+
if (!isChromatic()) {
|
|
1089
|
+
event.api.sizeColumnsToFit();
|
|
1090
|
+
}
|
|
1087
1091
|
}
|
|
1088
1092
|
},
|
|
1089
1093
|
[sizeColumns],
|
|
@@ -18,7 +18,9 @@ const ButtonCellRenderer = <TData extends GridBaseRow>(props: ICellRendererParam
|
|
|
18
18
|
};
|
|
19
19
|
api.addEventListener('cellFocused', checkFocus);
|
|
20
20
|
return () => {
|
|
21
|
-
api.
|
|
21
|
+
if (!api.isDestroyed()) {
|
|
22
|
+
api.removeEventListener('cellFocused', checkFocus);
|
|
23
|
+
}
|
|
22
24
|
};
|
|
23
25
|
}, [api, column, node.rowIndex]);
|
|
24
26
|
|
|
@@ -25,7 +25,11 @@ const BooleanCellRenderer = <TData extends GridBaseRow>(props: CustomCellEditorP
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
api.addEventListener('cellFocused', checkFocus);
|
|
28
|
-
return () =>
|
|
28
|
+
return () => {
|
|
29
|
+
if (!api.isDestroyed()) {
|
|
30
|
+
api.removeEventListener('cellFocused', checkFocus);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
29
33
|
}, [api, column, node.rowIndex]);
|
|
30
34
|
|
|
31
35
|
const isDisabled = !fnOrVar(colDef?.editable, props);
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ProcessCellForExportParams,
|
|
10
10
|
RowNode,
|
|
11
11
|
} from 'ag-grid-community';
|
|
12
|
+
import isChromatic from 'chromatic/isChromatic';
|
|
12
13
|
import debounce from 'debounce-promise';
|
|
13
14
|
import { compact, defer, delay, difference, filter, isEmpty, last, pull, remove, sortBy, sumBy } from 'lodash-es';
|
|
14
15
|
import { PropsWithChildren, ReactElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -463,6 +464,13 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
463
464
|
return null;
|
|
464
465
|
}
|
|
465
466
|
|
|
467
|
+
// Column widths are measured from rendered content, which is non-deterministic across
|
|
468
|
+
// Chromatic's environment. Skip measuring/resizing so snapshots stay stable at their
|
|
469
|
+
// configured widths, but still resolve with a width so callers don't retry forever.
|
|
470
|
+
if (isChromatic()) {
|
|
471
|
+
return { width: sumBy(gridApi.getColumnState(), (colState) => (colState.hide ? 0 : (colState.width ?? 0))) };
|
|
472
|
+
}
|
|
473
|
+
|
|
466
474
|
try {
|
|
467
475
|
const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
|
|
468
476
|
|
|
@@ -530,7 +538,7 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
530
538
|
*/
|
|
531
539
|
const sizeColumnsToFit = useCallback(
|
|
532
540
|
(paramsOrGridWidth?: ISizeColumnsToFitParams): void => {
|
|
533
|
-
if (gridApi && !gridApi?.isDestroyed()) {
|
|
541
|
+
if (gridApi && !gridApi?.isDestroyed() && !isChromatic()) {
|
|
534
542
|
gridApi.sizeColumnsToFit(paramsOrGridWidth);
|
|
535
543
|
}
|
|
536
544
|
},
|
|
@@ -654,13 +662,13 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
654
662
|
const nextColumn = focusedCell?.column;
|
|
655
663
|
const nextColDef = nextColumn?.getColDef();
|
|
656
664
|
const rowNode = focusedCell && gridApi.getDisplayedRowAtIndex(focusedCell?.rowIndex);
|
|
657
|
-
const popupable = String(nextColDef?.cellClass).indexOf(
|
|
658
|
-
return (
|
|
659
|
-
!!(rowNode && nextColumn && nextColDef) &&
|
|
665
|
+
const popupable = String(nextColDef?.cellClass).indexOf('GridCellEditableWithNoPopup') === -1;
|
|
666
|
+
return !!(rowNode && nextColumn && nextColDef) &&
|
|
660
667
|
nextColumn.isCellEditable(rowNode) &&
|
|
661
668
|
!nextColDef.cellEditorParams?.preventAutoEdit &&
|
|
662
669
|
!nextColDef.cellRendererParams?.editAction
|
|
663
|
-
|
|
670
|
+
? popupable
|
|
671
|
+
: null;
|
|
664
672
|
};
|
|
665
673
|
|
|
666
674
|
// Just in case I've missed something, we don't want the loop to hang everything
|
|
@@ -698,7 +706,7 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
698
706
|
|
|
699
707
|
// checkbox cells are editable but don't have a popup
|
|
700
708
|
// we need to end bulk editing and just select the cell
|
|
701
|
-
const editable = focusedCellIsEditable()
|
|
709
|
+
const editable = focusedCellIsEditable();
|
|
702
710
|
if (editable !== null) {
|
|
703
711
|
const focusedCell = gridApi.getFocusedCell();
|
|
704
712
|
if (focusedCell) {
|
|
@@ -708,7 +716,7 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
708
716
|
return false;
|
|
709
717
|
}
|
|
710
718
|
if (editable) {
|
|
711
|
-
await startCellEditing({rowId, colId: focusedCell.column.getColId()});
|
|
719
|
+
await startCellEditing({ rowId, colId: focusedCell.column.getColId() });
|
|
712
720
|
// Continue bulk edit
|
|
713
721
|
return true;
|
|
714
722
|
} else {
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
GridUpdatingContextProvider,
|
|
13
13
|
primitiveToSelectOption,
|
|
14
14
|
} from '../..';
|
|
15
|
-
import { expect, userEvent, waitFor } from 'storybook/test';
|
|
15
|
+
import { expect, userEvent, fireEvent, waitFor } from 'storybook/test';
|
|
16
16
|
|
|
17
17
|
import { waitForGridReady } from '../../utils/__tests__/storybookTestUtil';
|
|
18
18
|
|
|
@@ -132,23 +132,24 @@ export const _EditBoolean = GridPopoutEditBooleanTemplate.bind({});
|
|
|
132
132
|
_EditBoolean.play = waitForGridReady;
|
|
133
133
|
|
|
134
134
|
export const _EditBooleanRetainsFocusAfterToggle = GridPopoutEditBooleanTemplate.bind({});
|
|
135
|
-
_EditBooleanRetainsFocusAfterToggle.play = async (
|
|
136
|
-
await waitForGridReady(
|
|
137
|
-
const { canvasElement } = context;
|
|
135
|
+
_EditBooleanRetainsFocusAfterToggle.play = async ({ canvasElement }) => {
|
|
136
|
+
await waitForGridReady({ canvasElement });
|
|
138
137
|
|
|
139
138
|
// Use boldMultiSelect (no async delay) so the redraw happens immediately
|
|
140
139
|
const getBoolInput = () =>
|
|
141
140
|
canvasElement.querySelector('.ag-cell[col-id="boldMultiSelect"] input.ag-checkbox-input') as HTMLElement;
|
|
142
141
|
|
|
143
|
-
|
|
144
|
-
await
|
|
142
|
+
const button = canvasElement.querySelector('.ag-cell[col-id="boldMultiSelect"]') as HTMLElement;
|
|
143
|
+
await expect(button).toBeInTheDocument();
|
|
144
|
+
await fireEvent.click(button);
|
|
145
|
+
await waitFor(() => expect(getBoolInput()).toHaveFocus(), { timeout: 1500 });
|
|
145
146
|
|
|
146
147
|
// Space toggles the checkbox, which triggers redrawRows — ag-grid moves focus from the
|
|
147
148
|
// input to the cell div (role="gridcell"). The shared interval should detect this and restore focus.
|
|
148
|
-
await
|
|
149
|
+
await fireEvent.keyPress(getBoolInput(), { key: 'Space', code: 'KeySpace' });
|
|
149
150
|
|
|
150
151
|
// Re-query the input each retry since redraw replaces the DOM node
|
|
151
|
-
await waitFor(() => expect(getBoolInput()).toHaveFocus(), { timeout:
|
|
152
|
+
await waitFor(() => expect(getBoolInput()).toHaveFocus(), { timeout: 1500 });
|
|
152
153
|
};
|
|
153
154
|
|
|
154
155
|
const selectRow = async (canvasElement: HTMLElement, rowId: string) => {
|