Skip to content

Commit 5a9524c

Browse files
shipReview: Windows NextSteps feedback (#1316)
* chore: Update NextStepsGroup bottom margin * chore: Increase min-height of card * chore: Address d4 * fix: Bottom margin * fix: Add blur to click handler on ShowHideButton * fix: lint * chore: wat * fix: Focus-visible on ShowHideButton implementations. remove blur code * fix: lint * fix: card border color * Added a failing test case for favorites expansion * fixed favorites positioning --------- Co-authored-by: Shane Osbourne <[email protected]>
1 parent 7ef4778 commit 5a9524c

File tree

10 files changed

+91
-37
lines changed

10 files changed

+91
-37
lines changed

special-pages/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"prebuild": "node types.mjs && node translations.mjs",
1010
"build": "node index.mjs",
1111
"build.dev": "npm run build -- --env development",
12+
"lint-fix": "cd ../ && npm run lint-fix",
1213
"test-unit": "node --test unit-test/translations.mjs pages/duckplayer/unit-tests/embed-settings.mjs pages/new-tab/app/freemium-pir-banner/unit-tests/utils.spec.mjs",
1314
"test-int": "npm run test-unit && npm run build.dev && playwright test --grep-invert '@screenshots'",
1415
"test-int-x": "npm run test-int",

special-pages/pages/new-tab/app/components/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function App({ children }) {
2828

2929
return (
3030
<div class={cn(styles.layout)} ref={wrapperRef} data-drawer-visibility={visibility}>
31-
<main class={cn(styles.main)} data-customizer-kind={customizerKind}>
31+
<main class={cn(styles.main)} data-main-scroller data-customizer-kind={customizerKind}>
3232
<div class={styles.tube} data-platform={platformName}>
3333
<WidgetList />
3434
<CustomizerMenuPositionedFixed>

special-pages/pages/new-tab/app/components/ShowHide.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
}
5757
}
5858

59+
> * {
60+
pointer-events: none;
61+
}
62+
5963
svg {
6064
transition: transform .3s;
6165
}

special-pages/pages/new-tab/app/entry-points/nextSteps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { NextStepsCustomized } from '../next-steps/NextSteps.js';
44

55
export function factory() {
66
return (
7-
<Centered>
7+
<Centered data-entry-point="nextSteps">
88
<NextStepsCustomized />
99
</Centered>
1010
);

special-pages/pages/new-tab/app/favorites/components/Favorites.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,54 +179,62 @@ function Inner({ rows, safeAreaRef, rowHeight, add }) {
179179
// hold a mutable value that we update on resize
180180
const gridOffset = useRef(0);
181181

182-
// When called, make the expensive call to `getBoundingClientRect` to determine the offset of
183-
// the grid wrapper.
184-
function updateGlobals() {
182+
/**
183+
* When called, make the expensive call to `getBoundingClientRect` to determine the offset of
184+
* the grid wrapper.
185+
* @param {number} scrollY
186+
*/
187+
function updateGlobals(scrollY) {
185188
if (!safeAreaRef.current) return;
186189
const rec = safeAreaRef.current.getBoundingClientRect();
187-
gridOffset.current = rec.y + window.scrollY;
190+
gridOffset.current = rec.y + scrollY;
188191
}
189192

190-
// decide which the start/end indexes should be, based on scroll position.
191-
// NOTE: this is called on scroll, so must not incur expensive checks/measurements - math only!
192-
function setVisibleRows() {
193+
/**
194+
* decide which the start/end indexes should be, based on scroll position.
195+
* NOTE: this is called on scroll, so must not incur expensive checks/measurements - math only!
196+
* @param {number} scrollY
197+
*/
198+
function setVisibleRowsForOffset(scrollY) {
193199
if (!safeAreaRef.current) return console.warn('cannot access ref');
194200
if (!gridOffset.current) return console.warn('cannot access ref');
195201
const offset = gridOffset.current;
196-
const end = window.scrollY + window.innerHeight - offset;
202+
const end = scrollY + window.innerHeight - offset;
197203
let start;
198-
if (offset > window.scrollY) {
204+
if (offset > scrollY) {
199205
start = 0;
200206
} else {
201-
start = window.scrollY - offset;
207+
start = scrollY - offset;
202208
}
203209
const startIndex = Math.floor(start / rowHeight);
204210
const endIndex = Math.min(Math.ceil(end / rowHeight), rows.length);
205211
setVisibleRange({ start: startIndex, end: endIndex });
206212
}
207213

208214
useLayoutEffect(() => {
215+
const stableElement = document.querySelector('[data-main-scroller]');
216+
if (!stableElement) return console.warn('cannot find scrolling element');
209217
// always update globals first
210-
updateGlobals();
218+
updateGlobals(stableElement.scrollTop);
211219

212220
// and set visible rows once the size is known
213-
setVisibleRows();
221+
setVisibleRowsForOffset(stableElement.scrollTop);
214222

215223
const controller = new AbortController();
216224

217225
window.addEventListener(
218226
'resize',
219227
() => {
220-
updateGlobals();
221-
setVisibleRows();
228+
updateGlobals(stableElement.scrollTop);
229+
setVisibleRowsForOffset(stableElement.scrollTop);
222230
},
223231
{ signal: controller.signal },
224232
);
225233

226-
window.addEventListener(
234+
stableElement.addEventListener(
227235
'scroll',
228236
() => {
229-
setVisibleRows();
237+
setVisibleRowsForOffset(stableElement.scrollTop);
230238
},
231239
{ signal: controller.signal },
232240
);

special-pages/pages/new-tab/app/favorites/components/Favorites.module.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
opacity: 1;
1818
}
1919
}
20-
&:focus-within {
21-
.showhideVisible [aria-controls] {
22-
opacity: 1;
23-
}
24-
}
2520
}
2621

2722
.showhide {

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from '@playwright/test';
22

33
export class FavoritesPage {
4+
static ENTRY_POINT = '[data-entry-point="favorites"]';
45
/**
56
* @param {import("../../../integration-tests/new-tab.page.js").NewtabPage} ntp
67
*/
@@ -10,7 +11,7 @@ export class FavoritesPage {
1011

1112
async togglesExpansion() {
1213
const { page } = this.ntp;
13-
await page.getByLabel('Show more (10 remaining)').click();
14+
await this.showMore();
1415
await expect(page.getByLabel('Add Favorite')).toBeVisible();
1516
await page.getByLabel('Show less').click();
1617
await expect(page.getByLabel('Add Favorite')).not.toBeVisible();
@@ -36,12 +37,19 @@ export class FavoritesPage {
3637

3738
async addsAnItem() {
3839
const { page } = this.ntp;
39-
await page.pause();
40-
await page.getByLabel('Show more (10 remaining)').click();
40+
await this.showMore();
4141
await page.getByLabel('Add Favorite').click();
4242
await this.ntp.mocks.waitForCallCount({ method: 'favorites_add', count: 1 });
4343
}
4444

45+
/**
46+
* @param {number|string} count
47+
*/
48+
async showMore(count = '10') {
49+
const { page } = this.ntp;
50+
await page.locator(FavoritesPage.ENTRY_POINT).getByLabel(`Show more (${count} remaining)`).click();
51+
}
52+
4553
async rightClickInvokesContextMenuFor() {
4654
const first = this.nthFavorite(0);
4755
const second = this.nthFavorite(1);
@@ -263,4 +271,14 @@ export class FavoritesPage {
263271
},
264272
});
265273
}
274+
275+
async scrollToContainer() {
276+
const { page } = this.ntp;
277+
const rect = await page.locator(FavoritesPage.ENTRY_POINT).evaluate((e) => e.getBoundingClientRect());
278+
// scroll to the top of the container
279+
await page.evaluate((y) => window.scrollBy(0, y), rect.top);
280+
281+
// give chance for any DOM changes to occur
282+
await page.waitForTimeout(500);
283+
}
266284
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,35 @@ test.describe('newtab favorites', () => {
115115
await ntp.reducedMotion();
116116
await ntp.openPage({ favorites: 'fallbacks' });
117117
});
118+
test('expansion works with expanded items above', async ({ page }, workerInfo) => {
119+
const ntp = NewtabPage.create(page, workerInfo);
120+
await ntp.reducedMotion();
121+
122+
const favorites = new FavoritesPage(ntp);
123+
124+
// open the page with enough next-step + favorites for both to be expanded
125+
await ntp.openPage({
126+
nextSteps: ['bringStuff', 'defaultApp', 'blockCookies', 'duckplayer'],
127+
favorites: '16',
128+
});
129+
130+
// expand next-steps
131+
// todo: move this to a page-object in next-steps
132+
await page.locator('[data-entry-point="nextSteps"]').getByLabel('Show More', { exact: true }).click();
133+
134+
// first load should have 6
135+
await favorites.waitForNumFavorites(6);
136+
137+
// show more
138+
await favorites.showMore(10);
139+
140+
// now should have 16 rendered
141+
await favorites.waitForNumFavorites(16);
142+
143+
// scroll to the top of the favorites widget
144+
await favorites.scrollToContainer();
145+
146+
// assert there's still 16 showing
147+
await favorites.waitForNumFavorites(16);
148+
});
118149
});

special-pages/pages/new-tab/app/next-steps/components/NextSteps.module.css

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
justify-content: flex-start;
1010
align-items: center;
1111
text-align: center;
12+
backdrop-filter: blur(48px);
1213
max-width: calc(240 * var(--px-in-rem));
13-
min-height: calc(150 * var(--px-in-rem));
14+
min-height: calc(166 * var(--px-in-rem));
1415
font-size: var(--body-font-size);
1516
}
1617

@@ -137,6 +138,7 @@
137138
height: 100%;
138139
width: 100%;
139140
position: relative;
141+
margin-bottom: var(--sp-4);
140142

141143
&:hover {
142144
.showhide {
@@ -192,11 +194,6 @@
192194
opacity: 1;
193195
}
194196
}
195-
&:focus-within {
196-
.showhide [aria-controls] {
197-
opacity: 1;
198-
}
199-
}
200197
}
201198

202199
:root:has(body[data-platform-name="windows"]) {

special-pages/pages/new-tab/app/styles/ntp-theme.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
:root {
2-
--ntp-background-color: white;
3-
--ntp-surface-background-color: white;
2+
--ntp-background-color: var(--color-gray-0);
3+
--ntp-surface-background-color: var(--color-white-at-30);
44
--ntp-surfaces-panel-background-color: white;
5-
--ntp-surface-border-color: var(--color-black-at-6);
5+
--ntp-surface-border-color: var(--color-black-at-9);
66
--ntp-text-normal: var(--color-black-at-84);
77
--ntp-text-muted: var(--color-black-at-60);
88
--ntp-text-on-primary: var(--color-white-at-84);
@@ -36,9 +36,9 @@
3636

3737
@media (prefers-color-scheme: dark) {
3838
--ntp-background-color: var(--color-gray-85);
39-
--ntp-surface-background-color: #2a2a2a;
39+
--ntp-surface-background-color: var(--color-black-at-18);
4040
--ntp-surfaces-panel-background-color: #222222;
41-
--ntp-surface-border-color: var(--color-white-at-6);
41+
--ntp-surface-border-color: var(--color-white-at-9);
4242
--ntp-text-normal: var(--color-white-at-84);
4343
--ntp-text-muted: var(--color-white-at-60);
4444
--ntp-color-primary: var(--color-blue-30);

0 commit comments

Comments
 (0)