fix(editor): the strip stays below the top bar on scroll
This commit is contained in:
1 parent
62b400e876
commit
f2809f20ca
6 files changed
+153
-3
No files matched your search
@@ -563,3 +563,124 @@ test.describe('editor touch path (real browser)', () => {
|
||||
expect(Math.abs((await shownNumber(page, 'cx')) - 620)).toBeLessThan(3)
|
||||
})
|
||||
})
|
||||
|
||||
// U2 Task 14 (owner point 1): on the editable layout the strip stays right under the sticky
|
||||
// top bar at every scroll position, without moving anything in the flow.
|
||||
const VIEWPORTS = [
|
||||
{ width: 1024, height: 768 },
|
||||
{ width: 1180, height: 820 },
|
||||
{ width: 1280, height: 800 },
|
||||
]
|
||||
|
||||
/** Enough annotations for the overview to grow the page well past one screen. */
|
||||
const manyPoints = () =>
|
||||
Array.from({ length: 14 }, (_, i) =>
|
||||
pointOf(`pt-${i}`, 'main', { cx: 100 + i * 40, cy: 100, r: 10 }, `Pt ${i}`),
|
||||
)
|
||||
|
||||
/** The strip's and the bar's boxes, and what is painted at the strip's centre. */
|
||||
function stripGeometry(page: Page) {
|
||||
return page.evaluate(() => {
|
||||
const strip = document.querySelector('[data-testid="edit-strip"]')!
|
||||
const bar = document.querySelector(
|
||||
'header:has([data-testid="topbar-account"])',
|
||||
)!
|
||||
const box = strip.getBoundingClientRect()
|
||||
const hit = document.elementFromPoint(
|
||||
box.x + box.width / 2,
|
||||
box.y + box.height / 2,
|
||||
)
|
||||
return {
|
||||
barBottom: bar.getBoundingClientRect().bottom,
|
||||
top: box.top,
|
||||
bottom: box.bottom,
|
||||
covered: !hit || !strip.contains(hit),
|
||||
scrollY: window.scrollY,
|
||||
limit: document.documentElement.scrollHeight - window.innerHeight,
|
||||
innerHeight: window.innerHeight,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for (const viewport of VIEWPORTS) {
|
||||
test.describe(`the strip under the top bar at ${viewport.width} px (U2 Task 14)`, () => {
|
||||
test.use({
|
||||
locale: 'fr-FR',
|
||||
actionTimeout: 15_000,
|
||||
hasTouch: true,
|
||||
viewport,
|
||||
})
|
||||
test.beforeEach(async ({ context }, info) => {
|
||||
test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access
|
||||
await routeToSandbox(context)
|
||||
})
|
||||
test.afterEach(async ({ context }) => {
|
||||
await dropLateReplays(context)
|
||||
})
|
||||
|
||||
test('at every scroll step the strip is below the bar and visible; nothing shifts', async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
await open(page, ...manyPoints())
|
||||
await pickAnnotation(page, dict, 'Pt 0')
|
||||
await expect(selectionTag(page)).toContainText('Pt 0')
|
||||
const flowTop = (selector: string) =>
|
||||
page.evaluate(
|
||||
(css) =>
|
||||
document.querySelector(css)!.getBoundingClientRect().top +
|
||||
window.scrollY,
|
||||
selector,
|
||||
)
|
||||
const canvasTop = await flowTop('[data-testid="annotation-canvas"]')
|
||||
const asideTop = await flowTop('[data-annotation-aside="edit"]')
|
||||
const start = await stripGeometry(page)
|
||||
expect(start.limit, 'the page must scroll').toBeGreaterThan(300)
|
||||
|
||||
for (let y = 0; y <= start.limit + 150; y += 150) {
|
||||
await page.evaluate((to) => window.scrollTo(0, to), y)
|
||||
const now = await stripGeometry(page)
|
||||
const at = `scrollY ${now.scrollY}`
|
||||
expect(
|
||||
now.top,
|
||||
`strip top below the bar at ${at}`,
|
||||
).toBeGreaterThanOrEqual(now.barBottom - 0.5)
|
||||
expect(now.bottom, `strip bottom in view at ${at}`).toBeLessThanOrEqual(
|
||||
now.innerHeight,
|
||||
)
|
||||
expect(now.covered, `strip painted at ${at}`).toBe(false)
|
||||
}
|
||||
// Sticky leaves the flow alone: the canvas and the aside keep their place.
|
||||
expect(await flowTop('[data-testid="annotation-canvas"]')).toBe(canvasTop)
|
||||
expect(await flowTop('[data-annotation-aside="edit"]')).toBe(asideTop)
|
||||
|
||||
const bottom = (await stripGeometry(page)).scrollY
|
||||
const command = page
|
||||
.getByTestId('edit-strip')
|
||||
.getByRole('button', { name: dict['editor.annotations.properties'] })
|
||||
// A finger on a strip command after the scroll hits it (a hit check that had to
|
||||
// scroll again would move the page), and no box moves.
|
||||
const cdp = await context.newCDPSession(page)
|
||||
const box = (await command.boundingBox())!
|
||||
expect(
|
||||
box.y,
|
||||
'the command is in view, under the bar',
|
||||
).toBeGreaterThanOrEqual((await stripGeometry(page)).barBottom)
|
||||
await expectNoShift(page, async () => {
|
||||
const at = { x: box.x + box.width / 2, y: box.y + box.height / 2 }
|
||||
await cdp.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchStart',
|
||||
touchPoints: [at],
|
||||
})
|
||||
await cdp.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchEnd',
|
||||
touchPoints: [],
|
||||
})
|
||||
await expect(page.getByRole('dialog')).toBeVisible()
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(page.getByRole('dialog')).toHaveCount(0)
|
||||
})
|
||||
expect((await stripGeometry(page)).scrollY).toBe(bottom)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -39,7 +39,7 @@ export default function EditStrip({
|
||||
return (
|
||||
<div
|
||||
data-testid="edit-strip"
|
||||
className="flex h-16 items-center gap-3 overflow-hidden rounded-xl border border-[var(--color-border)] bg-[var(--color-surface)] px-3"
|
||||
className="flex h-[var(--edit-strip-height)] items-center gap-3 overflow-hidden rounded-xl border border-[var(--color-border)] bg-[var(--color-surface)] px-3 lg:sticky lg:top-[var(--shell-top-bar-height)] lg:z-[5]"
|
||||
>
|
||||
<Lead lead={lead} />
|
||||
<div data-testid="edit-strip-notice" className="min-w-0 flex-1">
|
||||
|
||||
@@ -86,7 +86,7 @@ export function TopBar({ shell, menuOpen, onOpenMenu }: TopBarProps) {
|
||||
const displayName = profile?.display_name ?? user?.email ?? ''
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-30 flex h-14 items-center gap-3 border-b border-[var(--color-border)] bg-[var(--color-surface)]/95 px-3 backdrop-blur-sm sm:px-6 pt-[env(safe-area-inset-top)]">
|
||||
<header className="sticky top-0 z-30 flex h-[var(--shell-top-bar-height)] items-center gap-3 border-b border-[var(--color-border)] bg-[var(--color-surface)]/95 px-3 backdrop-blur-sm sm:px-6 pt-[env(safe-area-inset-top)]">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpenMenu}
|
||||
|
||||
@@ -6,6 +6,22 @@ body,
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
/* The top bar's total height, read by the bar, by the editor strip's sticky top and by the
|
||||
scroll padding: one place, so they can never drift apart. */
|
||||
:root {
|
||||
--shell-top-bar-height: calc(3.5rem + env(safe-area-inset-top, 0px));
|
||||
--edit-strip-height: 4rem;
|
||||
}
|
||||
/* A focus or a scrollIntoView never lands a target under the bar, nor under the editor's
|
||||
sticky strip (its height plus the gap below it, space-y-3). */
|
||||
html {
|
||||
scroll-padding-top: calc(var(--shell-top-bar-height) + 0.75rem);
|
||||
}
|
||||
html:has([data-testid='edit-strip']) {
|
||||
scroll-padding-top: calc(
|
||||
var(--shell-top-bar-height) + var(--edit-strip-height) + 1.5rem
|
||||
);
|
||||
}
|
||||
/* A modal dialog is open (components/ui/ModalDialog): the page behind it does not scroll. */
|
||||
html:has(dialog:modal) {
|
||||
overflow: hidden;
|
||||
|
||||
@@ -1647,7 +1647,12 @@ describe('the strip', () => {
|
||||
|
||||
it('has a fixed height, hides its overflow and spans both columns', async () => {
|
||||
await mount()
|
||||
expect(strip()).toHaveClass('h-16', 'overflow-hidden')
|
||||
expect(strip()).toHaveClass(
|
||||
'h-[var(--edit-strip-height)]',
|
||||
'overflow-hidden',
|
||||
'lg:sticky',
|
||||
'lg:top-[var(--shell-top-bar-height)]',
|
||||
)
|
||||
expect(strip().nextElementSibling?.querySelector('aside')).not.toBeNull()
|
||||
expect(screen.queryByTestId('tracing-bar')).toBeNull()
|
||||
})
|
||||
|
||||
@@ -225,6 +225,14 @@ outline change (transforms and numbers only). The loupe goes away on the drop,
|
||||
on a cancel (a second finger, a lost capture, a document change) and at the end
|
||||
of the press. A mouse or pen drag shows no loupe.
|
||||
|
||||
The edit strip (U2 Task 14) stays under the shell's top bar from 1 024 px: it is
|
||||
`sticky` at `top: var(--shell-top-bar-height)`, opaque, with a z-index of 5 (above the
|
||||
drawing, under the loupe, the menus, the bar and the dialogs), and no ancestor sets an
|
||||
`overflow` other than visible. The bar's height (3.5 rem plus the safe-area inset) and the
|
||||
strip's (`--edit-strip-height`) are CSS variables of `styles/index.css`, which also feed the
|
||||
document's `scroll-padding-top`, so a focus or a `scrollIntoView` never lands under either.
|
||||
Below 1 024 px the strip is not sticky.
|
||||
|
||||
A creation (U2 Task 7, A2, A4, A12) is drawn by the overlay too, never by the
|
||||
core, since the new shape is not in the document until « Créer »:
|
||||
|
||||
|
||||
Reference in new issue
Block a user