-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
add "expand_all" toggle to datagrid header #8152
Changes from all commits
3bed72e
597dc5b
632ca8f
fb4dee0
f3130e5
96460c0
9799cc7
807c91c
ecb114b
554c630
b6209ed
acd9aae
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,37 @@ | ||
import * as React from 'react'; | ||
import { memo } from 'react'; | ||
import IconButton from '@mui/material/IconButton'; | ||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||
import { useTranslate, useExpandAll } from 'ra-core'; | ||
import { DatagridClasses } from './useDatagridStyles'; | ||
import clsx from 'clsx'; | ||
|
||
interface ExpandAllButtonProps { | ||
resource: string; | ||
ids: string[] | number[]; | ||
} | ||
|
||
const ExpandAllButton = ({ resource, ids }: ExpandAllButtonProps) => { | ||
const translate = useTranslate(); | ||
const [expanded, toggleExpanded] = useExpandAll(resource, ids); | ||
|
||
return ( | ||
<IconButton | ||
className={clsx(DatagridClasses.expandIcon, { | ||
[DatagridClasses.expanded]: expanded, | ||
})} | ||
aria-label={translate( | ||
expanded ? 'ra.action.close' : 'ra.action.expand' | ||
)} | ||
aria-expanded={expanded} | ||
tabIndex={-1} | ||
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. Why this tabindex? 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. dito 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. since ExpandRowButtons are not tab-selectable, the least i would do here is to stay consistent and keep tabindex = -1. |
||
aria-hidden="true" | ||
onClick={toggleExpanded} | ||
size="small" | ||
> | ||
<ExpandMoreIcon fontSize="inherit" /> | ||
</IconButton> | ||
); | ||
}; | ||
|
||
export default memo(ExpandAllButton); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as React from 'react'; | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
hiaselhans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import { Expand } from './Datagrid.stories'; | ||
|
||
describe('ExpandAllButton', () => { | ||
it('should expand all rows at once', async () => { | ||
render(<Expand />); | ||
const expand = () => { | ||
const button = screen.getAllByLabelText('ra.action.expand')[0]; | ||
fireEvent.click(button); | ||
}; | ||
const collapse = () => { | ||
const button = screen.getAllByLabelText('ra.action.close')[0]; | ||
fireEvent.click(button); | ||
}; | ||
|
||
const expectExpandedRows = (count: number) => { | ||
expect(screen.queryAllByTestId('ExpandPanel')).toHaveLength(count); | ||
}; | ||
|
||
expectExpandedRows(0); | ||
|
||
expand(); | ||
expectExpandedRows(4); | ||
|
||
collapse(); | ||
expectExpandedRows(0); | ||
}); | ||
}); |
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.
I don't understand this "unaffected".
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.
possible synonyms: