Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autoresize #463

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,4 @@ This will throw an exception if the row id is not found.

```tsx
window.__stepAgGrid.grids[dataTestId].scrollRowIntoViewById("1000")
```
```
11 changes: 9 additions & 2 deletions src/components/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ export const Grid = ({
const hasSetContentSizeEmpty = useRef(false);
const needsAutoSize = useRef(true);

const lastFullResize = useRef<number>();

const setInitialContentSize = useCallback(() => {
if (!gridDivRef.current?.clientWidth || rowData == null) {
// Don't resize grids if they are offscreen as it doesn't work.
Expand Down Expand Up @@ -193,8 +195,13 @@ export const Grid = ({
}
} else if (gridRendered === "rows-visible") {
if (!hasSetContentSize.current) {
hasSetContentSize.current = true;
params.onContentSize?.(result);
if (lastFullResize.current === result.width) {
hasSetContentSize.current = true;
params.onContentSize?.(result);
} else {
needsAutoSize.current = true;
}
lastFullResize.current = result.width;
}
} else {
// It should be impossible to get here
Expand Down
2 changes: 2 additions & 0 deletions src/contexts/GridPopoverContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface GridPopoverContextType<TData extends GridBaseRow> {
anchorRef: RefObject<Element>;
saving: boolean;
setSaving: (saving: boolean) => void;
colId: string;
field: keyof TData;
value: any;
data: TData;
Expand All @@ -18,6 +19,7 @@ export const GridPopoverContext = createContext<GridPopoverContextType<any>>({
anchorRef: { current: null },
saving: false,
setSaving: () => {},
colId: "",
field: "",
value: null,
data: {} as GridBaseRow,
Expand Down
3 changes: 3 additions & 0 deletions src/contexts/GridPopoverContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const GridPopoverContextProvider = ({ props, children }: PropsWithChildre
multiEdit ? sortBy(getFilteredSelectedRows(), (row) => row.id !== props.data.id) : [props.data as GridBaseRow],
[getFilteredSelectedRows, multiEdit, props.data],
);

const field = props.colDef?.field ?? "";
const colId = props.colDef?.colId ?? field ?? "";

const updateValue = useCallback(
async (saveFn: (selectedRows: any[]) => Promise<boolean>, tabDirection: 1 | 0 | -1): Promise<boolean> => {
Expand All @@ -44,6 +46,7 @@ export const GridPopoverContextProvider = ({ props, children }: PropsWithChildre
saving,
setSaving,
selectedRows,
colId,
field,
data: props.data,
value: props.value,
Expand Down
Loading