Skip to content

Commit

Permalink
refactor: use portal inside datagrid to ensure scoped styles still apply
Browse files Browse the repository at this point in the history
- misc cleanup
  • Loading branch information
mgadewoll committed Sep 13, 2024
1 parent c57438e commit 2ccfb4d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const EuiDataGridBodyCustomRender: FunctionComponent<
gridStyles,
className,
columnDragDrop,
wrapperRef,
}) => {
/**
* Columns & widths
Expand Down Expand Up @@ -107,6 +108,7 @@ export const EuiDataGridBodyCustomRender: FunctionComponent<
schemaDetectors,
gridStyles,
columnDragDrop,
wrapperRef,
});

const { footerRow } = useDataGridFooter({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export const EuiDataGridBodyVirtualized: FunctionComponent<EuiDataGridBodyProps>
schemaDetectors,
gridStyles,
columnDragDrop,
wrapperRef,
});

const { footerRow, footerRowHeight } = useDataGridFooter({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export const euiDataGridHeaderCellStyles = (euiThemeContext: UseEuiTheme) => {
}
`,
euiDataGridHeaderCellDraggable: css`
// override internal styling from @hello-pangea/dnd to ensure positioning
${logicalCSS('top', '0 !important;')}
/* override internal styling from @hello-pangea/dnd to ensure positioning */
${logicalCSS('top', '0 !important')}
display: 'flex';
${logicalCSS('width', '100%')}
`,
Expand All @@ -73,11 +73,10 @@ export const euiDataGridHeaderCellStyles = (euiThemeContext: UseEuiTheme) => {
align-items: center;
gap: ${euiTheme.size.xs};
border-radius: ${euiTheme.border.radius.small};
// font-weight: $euiFontWeightBold;
outline: none;
svg {
flex: 0 0 auto; // Ensure icon doesn't shrink
flex: 0 0 auto; /* Ensure icon doesn't shrink */
display: flex;
align-items: center;
justify-content: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('EuiDataGridHeaderCell', () => {
setColumnWidth: jest.fn(),
setVisibleColumns: jest.fn(),
switchColumnPos: jest.fn(),
wrapperRef: { current: null },
};

it('renders', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const EuiDataGridHeaderCell: FunctionComponent<EuiDataGridHeaderCellProps
schema,
schemaDetectors,
columnDragDrop,
wrapperRef,
}) => {
const { id, display, displayAsText, displayHeaderCellProps } = column;
const title = displayAsText || id;
Expand Down Expand Up @@ -346,7 +347,18 @@ export const EuiDataGridHeaderCell: FunctionComponent<EuiDataGridHeaderCellProps
* code duplication, using our own portal in place is cleaner.
* https://github.com/hello-pangea/dnd/blob/8f8cc785171bf67f660f7306d16666a1945e29a6/docs/guides/reparenting.md
*/
return isDragging ? <EuiPortal>{content}</EuiPortal> : content;
return isDragging ? (
<EuiPortal
insert={{
sibling: wrapperRef.current!, // using portal inside DataGrid to ensure styles are applied in scope
position: 'after',
}}
>
{content}
</EuiPortal>
) : (
content
);
}}
</EuiDraggable>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const euiDataGridHeaderStyles = (euiThemeContext: UseEuiTheme) => {
shade: css`
background-color: ${euiTheme.colors.lightestShade};
// ensure correct background on drag
/* ensure correct background on drag */
.euiDataGridHeaderCellDraggable .euiDataGridHeaderCell {
background-color: ${euiTheme.colors.lightestShade};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('EuiDataGridHeaderRow', () => {
setVisibleColumns: jest.fn(),
switchColumnPos: jest.fn(),
gridStyles: { header: 'shade' as const },
wrapperRef: { current: null },
};

it('renders', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

import classnames from 'classnames';
import React, { forwardRef, memo, useContext, useMemo } from 'react';

import { useEuiMemoizedStyles } from '../../../../services';
import { OnDragEndResponder } from '@hello-pangea/dnd';

import { useGeneratedHtmlId } from '../../../../services';
import { useEuiMemoizedStyles, useGeneratedHtmlId } from '../../../../services';
import { EuiDragDropContext, EuiDroppable } from '../../../drag_and_drop';
import { DataGridFocusContext } from '../../utils/focus';
import {
Expand Down Expand Up @@ -40,6 +38,7 @@ const EuiDataGridHeaderRow = memo(
schema,
schemaDetectors,
gridStyles,
wrapperRef,
columnDragDrop,
...rest
} = props;
Expand Down Expand Up @@ -94,6 +93,7 @@ const EuiDataGridHeaderRow = memo(
schema={schema}
schemaDetectors={schemaDetectors}
columnDragDrop={columnDragDrop}
wrapperRef={wrapperRef}
/>
)),
[
Expand All @@ -108,6 +108,7 @@ const EuiDataGridHeaderRow = memo(
setVisibleColumns,
sorting,
switchColumnPos,
wrapperRef,
]
);

Expand Down
1 change: 1 addition & 0 deletions packages/eui/src/components/datagrid/data_grid_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export interface EuiDataGridHeaderRowPropsSpecificProps {
setColumnWidth: (columnId: string, width: number) => void;
setVisibleColumns: (columnId: string[]) => void;
switchColumnPos: (colFromId: string, colToId: string) => void;
wrapperRef: MutableRefObject<HTMLDivElement | null>;
gridStyles: EuiDataGridStyle;
columnDragDrop?: boolean;
}
Expand Down

0 comments on commit 2ccfb4d

Please sign in to comment.