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 2 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` to `euiDataGrid` as prop to control the min size for grid controls ([#3527](https://github.com/elastic/eui/pull/3527))
mmourafiq marked this conversation as resolved.
Show resolved Hide resolved
- 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 `minSizeForControls` prop to control the min width to
mmourafiq marked this conversation as resolved.
Show resolved Hide resolved
enables/disables grid controls based on available width.
</p>
),
components: { DataGridContainer },
Expand Down
15 changes: 12 additions & 3 deletions src/components/datagrid/data_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ type CommonGridProps = CommonProps &
* A callback for when a column's size changes. Callback receives `{ columnId: string, width: number }`.
*/
onColumnResize?: EuiDataGridOnColumnResizeHandler;
/**
* Defines a control for the min size when the grid only shows the full screen button.
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
* Default to `MINIMUM_WIDTH_FOR_GRID_CONTROLS`.
*/
minSizeForControls?: number;
};

// This structure forces either aria-label or aria-labelledby to be defined
Expand Down Expand Up @@ -326,12 +331,13 @@ 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
width > minSizeForControls || isFullScreen
);
},
[setHasRoomForGridControls, isFullScreen]
Expand Down Expand Up @@ -593,11 +599,14 @@ export const EuiDataGrid: FunctionComponent<EuiDataGridProps> = props => {
);

// enables/disables grid controls based on available width
const minSizeForControls = typeof props.minSizeForControls === 'undefined' ?
mmourafiq marked this conversation as resolved.
Show resolved Hide resolved
MINIMUM_WIDTH_FOR_GRID_CONTROLS :
props.minSizeForControls;
const onResize = useOnResize(nextHasRoomForGridControls => {
if (nextHasRoomForGridControls !== hasRoomForGridControls) {
setHasRoomForGridControls(nextHasRoomForGridControls);
}
}, isFullScreen);
}, isFullScreen, minSizeForControls);

const handleGridKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
switch (e.keyCode) {
Expand Down