mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-03 16:16:59 +00:00
fix(files): keep the items a drag selection covers after letting go
This commit is contained in:
@@ -214,6 +214,21 @@ describe('FileBrowser', () => {
|
||||
expect(screen.getAllByRole('button', { name: /upload_files/ }).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('keeps a drag selection when the mouse is released', () => {
|
||||
const onClearSelection = vi.fn();
|
||||
const { onSetSelection } = renderBrowser({ props: { onClearSelection, selectedResources: new Set(['notes.txt']) } });
|
||||
const area = list().parentElement!;
|
||||
// jsdom lays everything out at 0,0, so a box from -5,-5 to 20,20 covers every row.
|
||||
fireEvent.mouseDown(area, { button: 0, clientX: -5, clientY: -5 });
|
||||
fireEvent.mouseMove(window, { clientX: 20, clientY: 20 });
|
||||
fireEvent.mouseUp(window, { clientX: 20, clientY: 20 });
|
||||
fireEvent.click(area);
|
||||
|
||||
expect(onSetSelection).toHaveBeenLastCalledWith(new Set(['Documents', 'notes.txt']));
|
||||
// Only the press that started the drag cleared the old selection.
|
||||
expect(onClearSelection).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('replaces the toolbar with selection actions when items are selected', () => {
|
||||
renderBrowser({ props: { selectedResources: new Set(['notes.txt']) } });
|
||||
const bar = screen.getByRole('toolbar', { name: 'selection_actions' });
|
||||
|
||||
@@ -1043,7 +1043,10 @@ export function FileBrowser({
|
||||
menu.openContextMenu(e, { kind: "empty" });
|
||||
}}
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget && selectedResources.size > 0 && !marquee) onClearSelection();
|
||||
// With a mouse, pressing on empty space already cleared the
|
||||
// selection, and the click that ends a drag-select lands here
|
||||
// too: clearing again would drop what was just selected.
|
||||
if (touch && e.target === e.currentTarget && selectedResources.size > 0) onClearSelection();
|
||||
}}
|
||||
onDragEnter={handleContentDragEnter}
|
||||
onDragOver={handleContentDragOver}
|
||||
|
||||
Reference in New Issue
Block a user