From e8b45646165e0a721bc0f0ac311fa061ca4ad9ca Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Tue, 10 Nov 2026 00:12:57 +0200 Subject: [PATCH] fix: the app's player starts right under the bar on a wide window too On a window 48rem wide or wider, the player screen had 1.25rem of padding above the player. It cost 20 px of the window's height, so a book whose chapter fit the window below the bar scrolled the window by that much. A message above the player now has that space as a top margin of its own. Closes #168. --- apps/demo/app/app.css | 8 +++++--- apps/demo/tests/app.test.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/apps/demo/app/app.css b/apps/demo/app/app.css index 3ed4b71f..43c0e155 100644 --- a/apps/demo/app/app.css +++ b/apps/demo/app/app.css @@ -234,13 +234,15 @@ .app .recent-list :focus-visible { outline-offset: -2px; } /* The player: as wide as the window on a phone, edge to edge, and at the page's width with room - around it on a larger screen. */ + at its sides on a larger screen. Never with room above it: there it costs the window's height, + and content that fits the window below the bar, as a book's chapter can, would scroll the + window by that much (#168). A message above the player keeps room of its own. */ .app[data-screen="player"] main { width: min(100%, var(--content)); padding: 0 0 env(safe-area-inset-bottom); } .app[data-screen="player"] .message { margin: 0.75rem var(--gutter) 0; } @media (min-width: 48rem) { - .app[data-screen="player"] main { width: min(100% - 2 * var(--gutter), var(--content)); padding-top: 1.25rem; } - .app[data-screen="player"] .message { margin: 0 0 1rem; } + .app[data-screen="player"] main { width: min(100% - 2 * var(--gutter), var(--content)); } + .app[data-screen="player"] .message { margin: 1.25rem 0 1rem; } } .app .stage { position: relative; } diff --git a/apps/demo/tests/app.test.ts b/apps/demo/tests/app.test.ts index 0982481a..199fc9c7 100644 --- a/apps/demo/tests/app.test.ts +++ b/apps/demo/tests/app.test.ts @@ -499,6 +499,35 @@ it('keeps the bar’s icons on its first row at every width, with Install off th await page.close() }) +it('puts the player right under the bar, and a message a little below it', async () => { + const { page, errors } = await openApp() + const choosing = page.waitForEvent('filechooser') + await page.click('#open') + await (await choosing).setFiles(QUIZ) + await playerIs(page, 'ready') + const belowBar = (selector: string) => + page.evaluate( + (selector) => Math.round(document.querySelector(selector)!.getBoundingClientRect().top - document.querySelector('.topbar')!.getBoundingClientRect().bottom), + selector + ) + + // Room above the player costs the window's height: content that fits the window below the bar, + // as a book's chapter can, would scroll it by that much (#168). On a phone and a wide window alike. + for (const width of [1000, 600]) { + await page.setViewportSize({ width, height: 760 }) + expect(await belowBar('h5p-player'), `at ${width}px`).toBe(0) + } + expect(errors).toEqual([]) + + // A message keeps room of its own, on the wide window. + await page.setViewportSize({ width: 1000, height: 760 }) + await page.goto(`${origin}/app/?src=/demo/content/missing.h5p`) + await playerIs(page, 'error') + expect(await seen(page)).toMatchObject({ screen: 'player', message: expect.stringMatching(/./) }) + expect(await belowBar('#message')).toBeGreaterThanOrEqual(16) + await page.close() +}) + it('has a menu and an About dialog that Escape closes', async () => { const { page } = await openApp() const open = (selector: string) => page.evaluate((selector) => document.querySelector(selector)!.matches(':popover-open, [open]'), selector)