Skip to content

Commit

Permalink
[EuiDataGrid] Add setIsFullScreen to ref API (#5531)
Browse files Browse the repository at this point in the history
* Expose `setIsFullScreen` to ref API

* Update documentation/examples
  • Loading branch information
Constance authored Jan 12, 2022
1 parent d96203d commit e5def1c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
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

0 comments on commit e5def1c

Please sign in to comment.