Skip to content
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
14 changes: 14 additions & 0 deletions x-pack/plugins/lens/public/drag_drop/drag_drop.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ describe('DragDrop', () => {
expect(preventDefault).not.toBeCalled();
});

test('removes selection on mouse down before dragging', async () => {
const removeAllRanges = jest.fn();
global.getSelection = jest.fn(() => (({ removeAllRanges } as unknown) as Selection));
const component = mount(
<DragDrop value={value} draggable={true} order={[2, 0, 1, 0]}>
<button>Hi!</button>
</DragDrop>
);

component.find('[data-test-subj="lnsDragDrop"]').simulate('mousedown');
expect(global.getSelection).toBeCalled();
expect(removeAllRanges).toBeCalled();
});

test('dragstart sets dragging in the context and calls it with proper params', async () => {
const setDragging = jest.fn();

Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/lens/public/drag_drop/drag_drop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ export const DragDrop = (props: BaseProps) => {
return <DropInner {...dropProps} />;
};

const removeSelectionBeforeDragging = () => {
const selection = window.getSelection();
if (selection) {
selection.removeAllRanges();
}
};

const DragInner = memo(function DragInner({
dataTestSubj,
className,
Expand Down Expand Up @@ -366,6 +373,7 @@ const DragInner = memo(function DragInner({
draggable: true,
onDragEnd: dragEnd,
onDragStart: dragStart,
onMouseDown: removeSelectionBeforeDragging,
})}
</div>
);
Expand Down