Skip to content

Commit ecd4914

Browse files
committed
click outside
1 parent d07f736 commit ecd4914

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

special-pages/pages/history/app/global/Providers/SelectionProvider.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,20 @@ export function useRowInteractions(mainRef) {
130130
}
131131
}
132132

133-
function handler(/** @type {MouseEvent} */ event) {
133+
function clickHandler(/** @type {MouseEvent} */ event) {
134134
if (!(event.target instanceof Element)) return;
135135
if (event.target.closest('button')) return;
136136
if (event.target.closest('a')) return;
137137
const itemRow = /** @type {HTMLElement|null} */ (event.target.closest('[data-history-entry][data-index]'));
138138
const selection = toRowSelection(itemRow);
139-
if (!itemRow || !selection) return;
140-
event.preventDefault();
141-
event.stopImmediatePropagation();
142-
const intention = eventToIntention(event, platformName);
143-
handleClickIntentions(intention, selection);
139+
if (selection) {
140+
event.preventDefault();
141+
event.stopImmediatePropagation();
142+
const intention = eventToIntention(event, platformName);
143+
handleClickIntentions(intention, selection);
144+
} else {
145+
dispatch({ kind: 'reset', reason: 'click occurred outside of rows' });
146+
}
144147
}
145148

146149
/**
@@ -259,7 +262,7 @@ export function useRowInteractions(mainRef) {
259262
if (handled) event.preventDefault();
260263
}
261264

262-
const onClick = useCallback(handler, [selected, anchorIndex, lastShiftRange, focusedIndex]);
265+
const onClick = useCallback(clickHandler, [selected, anchorIndex, lastShiftRange, focusedIndex]);
263266
const onKeyDown = useCallback(keyHandler, [selected, anchorIndex, lastShiftRange, focusedIndex]);
264267

265268
return { onClick, onKeyDown };

special-pages/pages/history/integration-tests/history-selections.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,11 @@ test.describe('history selections', () => {
194194
await hp.selectsRowIndexWithShift(2);
195195
await hp.menuForMultipleHistoryEntries(0, hp.ids(3), { action: 'delete' });
196196
});
197+
test('clicking outside of rows de-selects everything', async ({ page }, workerInfo) => {
198+
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
199+
await hp.openPage({});
200+
await hp.selectsRowIndex(0);
201+
await hp.clicksOutsideOfRows();
202+
await hp.selectedRowCountIs(0);
203+
});
197204
});

special-pages/pages/history/integration-tests/history.page.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,12 @@ export class HistoryTestPage {
542542
async submitSearchForm() {
543543
await this.page.getByRole('searchbox', { name: 'Search your history' }).press('Enter');
544544
}
545+
546+
async clicksOutsideOfRows() {
547+
await this.page.getByRole('main').click({ position: { x: 0, y: 0 } });
548+
}
549+
550+
async selectedRowCountIs(number) {
551+
await expect(this.main().locator('[aria-selected="true"]')).toHaveCount(number);
552+
}
545553
}

0 commit comments

Comments
 (0)