-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[XGrid] Close column header menu when resizing column #1989
Changes from all commits
52904c9
07d55f2
02f62c3
2675e86
74948d1
a18ce4e
99771c8
45b0a6b
d560e7f
7d04aab
b3051cb
f6d8f73
034d088
351dc20
eac7df2
43ed86c
38b4cc5
02d6a81
06fd468
81cfd59
7518461
b1508d7
6b38984
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import * as React from 'react'; | ||
import { | ||
createClientRenderStrictMode, | ||
// @ts-expect-error need to migrate helpers to TypeScript | ||
fireEvent, | ||
// @ts-expect-error need to migrate helpers to TypeScript | ||
screen, | ||
// @ts-expect-error need to migrate helpers to TypeScript | ||
waitFor, | ||
} from 'test/utils'; | ||
import { expect } from 'chai'; | ||
import { GRID_COLUMN_HEADER_SEPARATOR_RESIZABLE_CSS_CLASS, XGrid } from '@material-ui/x-grid'; | ||
import { getColumnHeaderCell } from 'test/utils/helperFn'; | ||
|
||
const isJSDOM = /jsdom/.test(window.navigator.userAgent); | ||
|
||
describe('<XGrid /> - Column Headers', () => { | ||
// TODO v5: replace with createClientRender | ||
const render = createClientRenderStrictMode(); | ||
|
||
const baselineProps = { | ||
autoHeight: isJSDOM, | ||
disableColumnResize: false, | ||
rows: [ | ||
{ | ||
id: 0, | ||
brand: 'Nike', | ||
foundationYear: 1964, | ||
}, | ||
{ | ||
id: 1, | ||
brand: 'Adidas', | ||
foundationYear: 1949, | ||
}, | ||
{ | ||
id: 2, | ||
brand: 'Puma', | ||
foundationYear: 1948, | ||
}, | ||
], | ||
}; | ||
|
||
describe('GridColumnHeaderMenu', () => { | ||
it('should close the menu of a column when resizing this column', async () => { | ||
render( | ||
<div style={{ width: 300, height: 500 }}> | ||
<XGrid | ||
{...baselineProps} | ||
columns={[ | ||
{ field: 'brand', resizable: true }, | ||
{ field: 'foundationYear', resizable: true }, | ||
]} | ||
/> | ||
</div>, | ||
); | ||
|
||
const columnCell = getColumnHeaderCell(0); | ||
|
||
const menuIconButton = columnCell.querySelector('button[aria-label="Menu"]'); | ||
|
||
fireEvent.click(menuIconButton); | ||
await waitFor(() => expect(screen.queryByRole('menu')).not.to.equal(null)); | ||
|
||
const separator = columnCell.querySelector('.MuiDataGrid-iconSeparator'); | ||
fireEvent.mouseDown(separator); | ||
// TODO remove mouseUp once useGridColumnReorder will handle cleanup properly | ||
fireEvent.mouseUp(separator); | ||
await waitFor(() => expect(screen.queryByRole('menu')).to.equal(null)); | ||
flaviendelangle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('should close the menu of a column when resizing another column', async () => { | ||
render( | ||
<div style={{ width: 300, height: 500 }}> | ||
<XGrid | ||
{...baselineProps} | ||
columns={[ | ||
{ field: 'brand', resizable: true }, | ||
{ field: 'foundationYear', resizable: true }, | ||
]} | ||
/> | ||
</div>, | ||
); | ||
|
||
const columnWithMenuCell = getColumnHeaderCell(0); | ||
const columnToResizeCell = getColumnHeaderCell(1); | ||
|
||
const menuIconButton = columnWithMenuCell.querySelector('button[aria-label="Menu"]'); | ||
|
||
fireEvent.click(menuIconButton); | ||
await waitFor(() => expect(screen.queryByRole('menu')).not.to.equal(null)); | ||
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. Ideally, we wouldn't need for an 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'm also in favor of fixing this behavior in a later PR to avoid blocking this one |
||
|
||
const separator = columnToResizeCell.querySelector( | ||
`.${GRID_COLUMN_HEADER_SEPARATOR_RESIZABLE_CSS_CLASS}`, | ||
); | ||
fireEvent.mouseDown(separator); | ||
// TODO remove mouseUp once useGridColumnReorder will handle cleanup properly | ||
fireEvent.mouseUp(separator); | ||
await waitFor(() => expect(screen.queryByRole('menu')).to.equal(null)); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will likely get this for free with a fix of #2007.