diff --git a/x-pack/plugins/lens/public/drag_drop/drag_drop.test.tsx b/x-pack/plugins/lens/public/drag_drop/drag_drop.test.tsx
index 2fc5efaa28b83..dd1e351b824fe 100644
--- a/x-pack/plugins/lens/public/drag_drop/drag_drop.test.tsx
+++ b/x-pack/plugins/lens/public/drag_drop/drag_drop.test.tsx
@@ -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(
+
+
+
+ );
+
+ 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();
diff --git a/x-pack/plugins/lens/public/drag_drop/drag_drop.tsx b/x-pack/plugins/lens/public/drag_drop/drag_drop.tsx
index 76e44c29eaed5..a376c962a7a1c 100644
--- a/x-pack/plugins/lens/public/drag_drop/drag_drop.tsx
+++ b/x-pack/plugins/lens/public/drag_drop/drag_drop.tsx
@@ -202,6 +202,13 @@ export const DragDrop = (props: BaseProps) => {
return ;
};
+const removeSelectionBeforeDragging = () => {
+ const selection = window.getSelection();
+ if (selection) {
+ selection.removeAllRanges();
+ }
+};
+
const DragInner = memo(function DragInner({
dataTestSubj,
className,
@@ -366,6 +373,7 @@ const DragInner = memo(function DragInner({
draggable: true,
onDragEnd: dragEnd,
onDragStart: dragStart,
+ onMouseDown: removeSelectionBeforeDragging,
})}
);