-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix column auto resize #3746
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
Merged
Merged
Fix column auto resize #3746
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
005c9f2
Use state to handle column auto resize
amanmahajan7 b66f3bd
Optimize
amanmahajan7 51c2bdd
Cleanup
amanmahajan7 d4afa2b
Test
amanmahajan7 ccaa437
Fix tests
amanmahajan7 69c46a2
Add flex columns test, make tests more robust
amanmahajan7 f60e759
Improve coverage
amanmahajan7 f736a3b
test `onColumnResize`
amanmahajan7 0e90906
Tweak
amanmahajan7 523ec5a
Rename helper
amanmahajan7 8a6bb28
Tweak comment
amanmahajan7 0bc54d9
Merge branch 'main' into am-double-double-click
amanmahajan7 58b38d3
Merge branch 'main' into am-double-double-click
amanmahajan7 8bae511
Address comments
amanmahajan7 012a2b9
tweak test
nstepien 3f04905
Revert "tweak test"
amanmahajan7 21205c8
Use `flushSync`
amanmahajan7 06d7e92
Address comments
amanmahajan7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,48 +66,54 @@ test('cannot not resize or auto resize column when resizable is not specified', | |
test('should resize column when dragging the handle', async () => { | ||
const onColumnResize = vi.fn(); | ||
setup<Row, unknown>({ columns, rows: [], onColumnResize }); | ||
const [, col2] = getHeaderCells(); | ||
const grid = getGrid(); | ||
expect(onColumnResize).not.toHaveBeenCalled(); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 200px' }); | ||
const [, col2] = getHeaderCells(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand, surely the cell element should still be in the document if we get it earlier, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be. I will investigate in a separate PR |
||
await resize({ column: col2, resizeBy: -50 }); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 150px' }); | ||
expect(onColumnResize).toHaveBeenCalledExactlyOnceWith(expect.objectContaining(columns[1]), 150); | ||
}); | ||
|
||
test('should use the maxWidth if specified', async () => { | ||
setup<Row, unknown>({ columns, rows: [] }); | ||
const [, col2] = getHeaderCells(); | ||
const grid = getGrid(); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 200px ' }); | ||
const [, col2] = getHeaderCells(); | ||
await resize({ column: col2, resizeBy: 1000 }); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 400px' }); | ||
}); | ||
|
||
test('should use the minWidth if specified', async () => { | ||
setup<Row, unknown>({ columns, rows: [] }); | ||
const [, col2] = getHeaderCells(); | ||
const grid = getGrid(); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 200px' }); | ||
const [, col2] = getHeaderCells(); | ||
await resize({ column: col2, resizeBy: -150 }); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 100px' }); | ||
}); | ||
|
||
test('should auto resize column when resize handle is double clicked', async () => { | ||
const onColumnResize = vi.fn(); | ||
setup<Row, unknown>({ | ||
columns, | ||
rows: [ | ||
{ | ||
col1: 1, | ||
col2: 'a'.repeat(50) | ||
} | ||
] | ||
], | ||
onColumnResize | ||
}); | ||
const [, col2] = getHeaderCells(); | ||
const grid = getGrid(); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 200px' }); | ||
const [, col2] = getHeaderCells(); | ||
await autoResize(col2); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 327.703px' }); | ||
expect(onColumnResize).toHaveBeenCalledExactlyOnceWith( | ||
expect.objectContaining(columns[1]), | ||
327.703125 | ||
); | ||
}); | ||
|
||
test('should use the maxWidth if specified on auto resize', async () => { | ||
|
@@ -120,9 +126,9 @@ test('should use the maxWidth if specified on auto resize', async () => { | |
} | ||
] | ||
}); | ||
const [, col2] = getHeaderCells(); | ||
const grid = getGrid(); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 200px' }); | ||
const [, col2] = getHeaderCells(); | ||
await autoResize(col2); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 400px' }); | ||
}); | ||
|
@@ -137,9 +143,57 @@ test('should use the minWidth if specified on auto resize', async () => { | |
} | ||
] | ||
}); | ||
const [, col2] = getHeaderCells(); | ||
const grid = getGrid(); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 200px' }); | ||
const [, col2] = getHeaderCells(); | ||
await autoResize(col2); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 100px' }); | ||
}); | ||
|
||
test('should remeasure flex columns when resizing a column', async () => { | ||
const onColumnResize = vi.fn(); | ||
setup< | ||
{ | ||
readonly col1: string; | ||
readonly col2: string; | ||
readonly col3: string; | ||
}, | ||
unknown | ||
>({ | ||
columns: [ | ||
{ | ||
key: 'col1', | ||
name: 'col1', | ||
resizable: true | ||
}, | ||
{ | ||
key: 'col2', | ||
name: 'col2', | ||
resizable: true | ||
}, | ||
{ | ||
key: 'col3', | ||
name: 'col3', | ||
resizable: true | ||
} | ||
], | ||
rows: [ | ||
{ | ||
col1: 'a'.repeat(10), | ||
col2: 'a'.repeat(10), | ||
col3: 'a'.repeat(10) | ||
} | ||
], | ||
onColumnResize | ||
}); | ||
const grid = getGrid(); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '639.328px 639.328px 639.344px' }); | ||
const [col1] = getHeaderCells(); | ||
await autoResize(col1); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '79.1406px 919.422px 919.438px' }); | ||
expect(onColumnResize).toHaveBeenCalledOnce(); | ||
// onColumnResize is not called if width is not changed | ||
await autoResize(col1); | ||
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '79.1406px 919.422px 919.438px' }); | ||
expect(onColumnResize).toHaveBeenCalledOnce(); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.