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

fix(DragDropSort): fix positioning of DragOverlay #10283

Merged
merged 1 commit into from
Apr 26, 2024
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { css } from '@patternfly/react-styles';
import {
DndContext,
Expand All @@ -22,6 +23,7 @@ import { Draggable } from './Draggable';
import { DraggableDataListItem } from './DraggableDataListItem';
import { DraggableDualListSelectorListItem } from './DraggableDualListSelectorListItem';
import styles from '@patternfly/react-styles/css/components/DragDrop/drag-drop';
import { canUseDOM } from '@patternfly/react-core';

export type DragDropSortDragEndEvent = DragEndEvent;
export type DragDropSortDragStartEvent = DragStartEvent;
Expand Down Expand Up @@ -135,6 +137,8 @@ export const DragDropSort: React.FunctionComponent<DragDropSortProps> = ({
);
};

const dragOverlay = <DragOverlay>{activeId && getDragOverlay()}</DragOverlay>;

const renderedChildren = (
<SortableContext items={itemIds} strategy={verticalListSortingStrategy} id="droppable">
{items.map((item: DraggableObject) => {
Expand All @@ -159,7 +163,7 @@ export const DragDropSort: React.FunctionComponent<DragDropSortProps> = ({
);
}
})}
<DragOverlay>{activeId && getDragOverlay()}</DragOverlay>
{canUseDOM ? ReactDOM.createPortal(dragOverlay, document.getElementById('root')) : dragOverlay}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it might be worth adding a prop to be able to customize the element passed to createPortal, though also may be something to wait and see if anyone mentions any issue with it. Not a blocker for me to keep this as-is, so unless anyone else would want to see that update ☑️

</SortableContext>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import React from 'react';
import { render } from '@testing-library/react';
import { DragDropSort } from '../';

jest.mock('react-dom', () => ({
...jest.requireActual('react-dom'),
createPortal: jest.fn((node) => node)
}));

test('renders some divs', () => {
const { asFragment } = render(
<div className="pf-c-droppable pf-m-dragging">
Expand Down
Loading