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

[EuiDataGrid] Add setIsFullScreen to ref API #5531

Merged
merged 2 commits into from
Jan 12, 2022
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
10 changes: 10 additions & 0 deletions src-docs/src/views/datagrid/datagrid_ref_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const dataGridRefSource = require('!!raw-loader!./ref');
const dataGridRefSnippet = `const dataGridRef = useRef();
<EuiDataGrid ref={dataGridRef} {...props} />

// Mnaually toggle the data grid's full screen state
dataGridRef.current.setIsFullScreen(true);

// Mnaually focus a specific cell within the data grid
dataGridRef.current.setFocusedCell({ rowIndex, colIndex });
`;
Expand All @@ -37,6 +40,13 @@ export const DataGridRefExample = {
the <EuiCode>ref</EuiCode> prop of EuiDataGrid. These methods are:
</p>
<ul>
<li>
<p>
<EuiCode>setIsFullScreen(isFullScreen)</EuiCode> - controls the
full screen state of the data grid. Accepts a true/false boolean
flag.
</p>
</li>
<li>
<EuiCode>setFocusedCell({'{ rowIndex, colIndex }'})</EuiCode> -
focuses the specified cell in the grid.
Expand Down
8 changes: 8 additions & 0 deletions src-docs/src/views/datagrid/ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ export default () => {
Set cell focus
</EuiButton>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton
size="s"
onClick={() => dataGridRef.current.setIsFullScreen(true)}
>
Set grid to full screen
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer />

Expand Down
1 change: 1 addition & 0 deletions src/components/datagrid/data_grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,7 @@ describe('EuiDataGrid', () => {
);

expect(gridRef.current).toEqual({
setIsFullScreen: expect.any(Function),
setFocusedCell: expect.any(Function),
});
});
Expand Down
1 change: 1 addition & 0 deletions src/components/datagrid/data_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export const EuiDataGrid = forwardRef<EuiDataGridRefProps, EuiDataGridProps>(
useImperativeHandle(
ref,
() => ({
setIsFullScreen,
setFocusedCell: ({ rowIndex, colIndex }) => {
focusContext.setFocusedCell([colIndex, rowIndex]);
},
Expand Down
4 changes: 4 additions & 0 deletions src/components/datagrid/data_grid_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ export type EuiDataGridProps = OneOf<
>;

export interface EuiDataGridRefProps {
/**
* Allows manually controlling the full-screen state of the grid.
*/
setIsFullScreen: (isFullScreen: boolean) => void;
/**
* Allows manually focusing the specified cell in the grid.
*
Expand Down