Skip to content

Commit cf1dc4a

Browse files
committed
fix middle click
1 parent 672b19e commit cf1dc4a

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

special-pages/pages/new-tab/app/activity/components/Activity.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,26 @@ import { ActivityInteractionsContext } from '../../burning/ActivityInteractionsC
3030
* Renders the Activity component with associated heading and body, managing interactivity and state.
3131
*
3232
* @param {Object} props - Object containing all properties required by the Activity component.
33-
* @param {(evt: MouseEvent) => void} props.didClick - Callback function triggered when the root element is clicked.
3433
* @param {Expansion} props.expansion - String indicating the expansion state of the activity, such as 'expanded' or 'collapsed'.
3534
* @param {() => void} props.toggle - Callback function to handle the expansion/collapse action.
3635
* @param {number} props.trackerCount - Object representing the tracker count for the activity.
3736
* @param {number} props.itemCount - Object representing the count of items in the activity.
3837
* @param {boolean} props.batched - Boolean indicating whether the activity uses batched loading.
3938
* @param {import("preact").ComponentChild} [props.children]
4039
*/
41-
export function Activity({ didClick, expansion, toggle, trackerCount, itemCount, batched, children }) {
40+
export function Activity({ expansion, toggle, trackerCount, itemCount, batched, children }) {
4241
// see: https://www.w3.org/WAI/ARIA/apg/patterns/accordion/examples/accordion/
4342
const expanded = expansion === 'expanded';
4443
const WIDGET_ID = useId();
4544
const TOGGLE_ID = useId();
45+
const { didClick } = useContext(ActivityInteractionsContext);
46+
47+
const ref = useRef(null);
48+
useOnMiddleClick(ref, didClick);
49+
4650
return (
4751
<Fragment>
48-
<div class={styles.root} onClick={didClick}>
52+
<div class={styles.root} onClick={didClick} ref={ref}>
4953
<ActivityHeading
5054
trackerCount={trackerCount}
5155
itemCount={itemCount}
@@ -240,10 +244,6 @@ export function ActivityConfigured({ expansion, toggle, children }) {
240244
const batched = useBatchedActivityApi();
241245

242246
const { activity } = useContext(NormalizedDataContext);
243-
const { didClick } = useContext(ActivityInteractionsContext);
244-
245-
const ref = useRef(/** @type {HTMLUListElement|null} */ (null));
246-
useOnMiddleClick(ref, didClick);
247247

248248
const count = useComputed(() => {
249249
return activity.value.totalTrackers;
@@ -254,14 +254,7 @@ export function ActivityConfigured({ expansion, toggle, children }) {
254254
});
255255

256256
return (
257-
<Activity
258-
batched={batched}
259-
itemCount={itemCount.value}
260-
trackerCount={count.value}
261-
expansion={expansion}
262-
toggle={toggle}
263-
didClick={didClick}
264-
>
257+
<Activity batched={batched} itemCount={itemCount.value} trackerCount={count.value} expansion={expansion} toggle={toggle}>
265258
{children}
266259
</Activity>
267260
);

special-pages/pages/new-tab/app/activity/integration-tests/activity.page.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export class ActivityPage {
193193
await page.getByText('example.com').click();
194194
await page.getByText('example.com').click({ modifiers: ['Meta'] });
195195
await page.getByText('example.com').click({ modifiers: ['Shift'] });
196+
await page.getByText('example.com').click({ button: 'middle' });
196197
await this._opensMainLink();
197198
}
198199
async _opensMainLink() {
@@ -213,6 +214,11 @@ export class ActivityPage {
213214
url,
214215
target: 'new-window',
215216
});
217+
218+
expect(calls[3].payload.params).toStrictEqual({
219+
url,
220+
target: 'new-window',
221+
});
216222
}
217223

218224
async opensLinkFromHistory() {

special-pages/pages/new-tab/app/favorites/integration-tests/favorites.page.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export class FavoritesPage {
2626

2727
async opensInNewWindow() {
2828
await this.nthFavorite(0).click({ modifiers: ['Shift'] });
29-
const calls = await this.ntp.mocks.waitForCallCount({ method: 'favorites_open', count: 1 });
29+
await this.nthFavorite(0).click({ button: 'middle' });
30+
const calls = await this.ntp.mocks.waitForCallCount({ method: 'favorites_open', count: 2 });
3031
expect(calls[0].payload.params).toStrictEqual({ id: 'id-many-1', url: 'https://example.com/?id=id-many-1', target: 'new-window' });
32+
expect(calls[1].payload.params).toStrictEqual({ id: 'id-many-1', url: 'https://example.com/?id=id-many-1', target: 'new-window' });
3133
}
3234

3335
async opensInSameTab() {

0 commit comments

Comments
 (0)