mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Lens] fix selection when dragging (#93034)
This commit is contained in:
parent
d7cac22ba2
commit
657c273866
2 changed files with 22 additions and 0 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
@ -366,6 +373,7 @@ const DragInner = memo(function DragInner({
|
|||
draggable: true,
|
||||
onDragEnd: dragEnd,
|
||||
onDragStart: dragStart,
|
||||
onMouseDown: removeSelectionBeforeDragging,
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue