Skip to content

Commit

Permalink
Correctly account for gridStyle.border
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Jan 26, 2022
1 parent 2655cf5 commit 60eac2e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/components/datagrid/_data_grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@
bottom: 0;
left: 0;

// Ensure the underlying grid is still interactable
pointer-events: none;

// Ensure the scrolling data grid body always has border edges
// regardless of cell position
box-shadow: inset 0 0 0 $euiBorderWidthThin $euiBorderColor;
// Note that this *must* be an inset `box-shadow` and not `border`, because
// border will affect the relative position of the child scroll bar overlays
// and cause them to be off by the width of the border

// Ensure the underlying grid is still interactable
pointer-events: none;
// For grids with horizontal-only borders, only render a bottom 'border'
.euiDataGrid--bordersHorizontal & {
box-shadow: inset 0 (-2 * $euiBorderWidthThin) 0 (-1 * $euiBorderWidthThin) $euiBorderColor;
}

// Ensure the horizontal scrollbar has a top border
.euiDataGrid__scrollBarOverlayBottom {
Expand Down
2 changes: 1 addition & 1 deletion src/components/datagrid/body/data_grid_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export const EuiDataGridBody: FunctionComponent<EuiDataGridBodyProps> = (
hasVerticalScroll,
hasHorizontalScroll,
scrollBorderOverlay,
} = useScrollBars(outerGridRef);
} = useScrollBars(outerGridRef, gridStyles.border);

/**
* Widths
Expand Down
10 changes: 10 additions & 0 deletions src/components/datagrid/utils/scrolling.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ describe('useScrollBars', () => {
});
});

describe('if the grid does not display borders', () => {
it('does not render anything', () => {
const { scrollBorderOverlay } = testCustomHook(() =>
useScrollBars(mockOuterGridRef, 'none')
);

expect(scrollBorderOverlay).toEqual(null);
});
});

describe('if the grid scrolls but has inline scrollbars & no scrollbar width/height', () => {
it('renders a single overlay with borders for the outermost grid', () => {
const { scrollBorderOverlay } = testCustomHook(() =>
Expand Down
15 changes: 13 additions & 2 deletions src/components/datagrid/utils/scrolling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import React, {
ReactNode,
} from 'react';
import { VariableSizeGrid as Grid } from 'react-window';
import { EuiDataGridStyle } from '../data_grid_types';
import { DataGridFocusContext } from './focus';

interface ScrollCellIntoView {
Expand Down Expand Up @@ -178,7 +179,8 @@ export const useScrollCellIntoView = ({
* Checks whether the current grid scrolls and/or has scrollbars
*/
export const useScrollBars = (
outerGridRef: MutableRefObject<HTMLDivElement | null>
outerGridRef: MutableRefObject<HTMLDivElement | null>,
borderStyle: EuiDataGridStyle['border'] = 'all'
): {
scrollBarHeight: number;
scrollBarWidth: number;
Expand Down Expand Up @@ -210,6 +212,9 @@ export const useScrollBars = (
if (!hasHorizontalScroll && !hasVerticalScroll) {
return null; // Nothing to render if the grid doesn't scroll
}
if (borderStyle === 'none') {
return null; // Nothing to render if the grid doesn't use borders
}
return (
<div className="euiDataGrid__scrollOverlay" role="presentation">
{scrollBarHeight > 0 && (
Expand All @@ -226,7 +231,13 @@ export const useScrollBars = (
)}
</div>
);
}, [hasHorizontalScroll, hasVerticalScroll, scrollBarHeight, scrollBarWidth]);
}, [
hasHorizontalScroll,
hasVerticalScroll,
scrollBarHeight,
scrollBarWidth,
borderStyle,
]);

return {
scrollBarHeight,
Expand Down

0 comments on commit 60eac2e

Please sign in to comment.