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

Add minSizeForControls to euiDataGrid #3527

Merged
merged 7 commits into from
Jun 2, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `minSizeForControls` prop to `EuiDataGrid` to control the minimum width for showing grid controls ([#3527](https://github.com/elastic/eui/pull/3527))
- Passed `getSelectedOptionForSearchValue` to `EuiComboBoxOptionsList` as prop ([#3501](https://github.com/elastic/eui/pull/3501))
- Added `appendIconComponentCache` function to allow manual pre-emptive loading of source elements into the `EuiIcon` cache ([#3481](https://github.com/elastic/eui/pull/3481))
- Added `initialSelected` to `EuiTableSelectionType` properties to set initial selected checkboxes for `EuiBasicTable` ([#3418](https://github.com/elastic/eui/pull/3418))
Expand Down
4 changes: 3 additions & 1 deletion src-docs/src/views/datagrid/datagrid_styling_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ export const DataGridStylingExample = {
text: (
<p>
When wrapped inside a container, like a dashboard panel, the grid will
start hiding controls and adopt a more strict flex layout
start hiding controls and adopt a more strict flex layout. Use the
<EuiCode>minSizeForControls</EuiCode> prop to control the min width to
enables/disables grid controls based on available width.
</p>
),
components: { DataGridContainer },
Expand Down
32 changes: 20 additions & 12 deletions src/components/datagrid/data_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ type CommonGridProps = CommonProps &
* A callback for when a column's size changes. Callback receives `{ columnId: string, width: number }`.
*/
onColumnResize?: EuiDataGridOnColumnResizeHandler;
/**
* Defines a minimum width for the grid to show all controls in its header.
*/
minSizeForControls?: number;
};

// This structure forces either aria-label or aria-labelledby to be defined
Expand Down Expand Up @@ -326,15 +330,14 @@ function useColumnWidths(

function useOnResize(
setHasRoomForGridControls: (hasRoomForGridControls: boolean) => void,
isFullScreen: boolean
isFullScreen: boolean,
minSizeForControls: number
) {
return useCallback(
({ width }: { width: number }) => {
setHasRoomForGridControls(
width > MINIMUM_WIDTH_FOR_GRID_CONTROLS || isFullScreen
);
setHasRoomForGridControls(width > minSizeForControls || isFullScreen);
},
[setHasRoomForGridControls, isFullScreen]
[setHasRoomForGridControls, isFullScreen, minSizeForControls]
);
}

Expand Down Expand Up @@ -592,13 +595,6 @@ export const EuiDataGrid: FunctionComponent<EuiDataGridProps> = props => {
[headerIsInteractive, setHeaderIsInteractive, focusedCell, setFocusedCell]
);

// enables/disables grid controls based on available width
const onResize = useOnResize(nextHasRoomForGridControls => {
if (nextHasRoomForGridControls !== hasRoomForGridControls) {
setHasRoomForGridControls(nextHasRoomForGridControls);
}
}, isFullScreen);

const handleGridKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
switch (e.keyCode) {
case keyCodes.ESCAPE:
Expand Down Expand Up @@ -626,9 +622,21 @@ export const EuiDataGrid: FunctionComponent<EuiDataGridProps> = props => {
inMemory,
popoverContents,
onColumnResize,
minSizeForControls = MINIMUM_WIDTH_FOR_GRID_CONTROLS,
...rest
} = props;

// enables/disables grid controls based on available width
const onResize = useOnResize(
nextHasRoomForGridControls => {
if (nextHasRoomForGridControls !== hasRoomForGridControls) {
setHasRoomForGridControls(nextHasRoomForGridControls);
}
},
isFullScreen,
minSizeForControls
);

const [columnWidths, setColumnWidth] = useColumnWidths(
columns,
onColumnResize
Expand Down