Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix PageHeader sticky positioning in React dashboard (#14218)
Damian Legawiec78ca0937d089
diff --git a/packages/dashboard-core/src/components/page-header.tsx b/packages/dashboard-core/src/components/page-header.tsxindex 8145dbca1e..c3ded4e335 100644--- a/packages/dashboard-core/src/components/page-header.tsx+++ b/packages/dashboard-core/src/components/page-header.tsx@@ -137,7 +137,7 @@ export function PageHeader({// the same hairline used elsewhere in the app.<headerclassName={cn(- 'sticky top-(--spacing-header-height) z-20 -mx-4 -mt-4 flex items-start gap-3 bg-background px-4 pt-4 pb-3 lg:-mx-6 lg:-mt-6 lg:px-6 lg:pt-6',+ 'sticky top-header-height z-20 -mx-4 -mt-4 flex items-start gap-3 bg-background px-4 pt-4 pb-3 lg:-mx-6 lg:-mt-6 lg:px-6 lg:pt-6','after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-border after:opacity-0 after:transition-opacity after:duration-150 after:[mask-image:linear-gradient(to_right,transparent,black_8%,black_92%,transparent)]',scrolled && 'after:opacity-100',)}diff --git a/packages/dashboard-ui/src/styles.css b/packages/dashboard-ui/src/styles.cssindex 9c8f3fc921..5fa1852af6 100644--- a/packages/dashboard-ui/src/styles.css+++ b/packages/dashboard-ui/src/styles.css@@ -250,18 +250,18 @@@apply font-sans antialiased;text-rendering: optimizeLegibility;overflow-y: scroll;+ /* Clip horizontal overflow at the document root so wide tables on mobile+ * can't widen the page. Must live on <html>, not <body>: `overflow-x:+ * hidden` on body makes `overflow-y` compute to `auto`, turning body into+ * a scroll container while the document actually scrolls on html — which+ * breaks `position: sticky` for PageHeader and other descendants. */+ overflow-x: clip;+ max-width: 100vw;}body {@apply bg-background text-foreground text-base;line-height: 1.5;- /* Lock body to the visible viewport width. Without this an overflowing- * descendant (a wide table on mobile) lets the body widen — and- * +position: fixed+ children center against +body+, not the viewport,- * landing off-screen. The descendant stays scrollable inside its own- * overflow container. */- overflow-x: hidden;- max-width: 100vw;}/* Headings — semibold (600) like Rails admin */diff --git a/packages/dashboard/e2e/products-edit-media-variants.spec.ts b/packages/dashboard/e2e/products-edit-media-variants.spec.tsindex 7a574f7889..9dc887c923 100644--- a/packages/dashboard/e2e/products-edit-media-variants.spec.ts+++ b/packages/dashboard/e2e/products-edit-media-variants.spec.ts@@ -4,6 +4,7 @@ import { expect, test } from '@playwright/test'import { login } from './helpers'import {addOptionToVariants,+ clickMediaThumbnailAction,createProduct,mediaCard,seedOptionType,@@ -49,8 +50,7 @@ test.describe('edit product — media variant linking', () => {await expect(media.locator('img[src]').first()).toBeVisible({ timeout: 30_000 })// Open the per-image edit sheet via the hover-revealed Edit button.- await media.locator('img[src]').first().hover()- await media.getByRole('button', { name: /^edit image$/i }).click()+ await clickMediaThumbnailAction(media, 'edit')await expect(page.getByRole('heading', { name: /^edit media$/i })).toBeVisible()// The "Assigned variants" pill row shows one button per variant. The@@ -76,8 +76,7 @@ test.describe('edit product — media variant linking', () => {// Reload, reopen the sheet, assert Red is still pressed and Blue is not.await page.reload()await expect(media.locator('img[src]').first()).toBeVisible({ timeout: 30_000 })- await media.locator('img[src]').first().hover()- await media.getByRole('button', { name: /^edit image$/i }).click()+ await clickMediaThumbnailAction(media, 'edit')await expect(page.getByRole('heading', { name: /^edit media$/i })).toBeVisible()await expect(redPill).toHaveAttribute('aria-pressed', 'true')@@ -104,8 +103,7 @@ test.describe('edit product — media variant linking', () => {await expect(media.locator('img[src]').first()).toBeVisible({ timeout: 30_000 })// Open the sheet, type new alt text, click Done.- await media.locator('img[src]').first().hover()- await media.getByRole('button', { name: /^edit image$/i }).click()+ await clickMediaThumbnailAction(media, 'edit')const sheet = page.getByRole('dialog')const altInput = sheet.getByRole('textbox')const newAlt = `Alt text ${Date.now()}`@@ -122,8 +120,7 @@ test.describe('edit product — media variant linking', () => {// Reload and reopen the sheet — alt persisted.await page.reload()await expect(media.locator('img[src]').first()).toBeVisible({ timeout: 30_000 })- await media.locator('img[src]').first().hover()- await media.getByRole('button', { name: /^edit image$/i }).click()+ await clickMediaThumbnailAction(media, 'edit')await expect(sheet.getByRole('textbox')).toHaveValue(newAlt)// ---- Regression: Cancel after editing must actually discard. ----@@ -139,8 +136,7 @@ test.describe('edit product — media variant linking', () => {// true — the merchant can click Save to commit a no-op, that's an// acceptable trade-off for a per-field-scoped restore that doesn't// accidentally wipe sibling edits.)- await media.locator('img[src]').first().hover()- await media.getByRole('button', { name: /^edit image$/i }).click()+ await clickMediaThumbnailAction(media, 'edit')await expect(sheet.getByRole('textbox')).toHaveValue(newAlt)})})diff --git a/packages/dashboard/e2e/products-helpers.ts b/packages/dashboard/e2e/products-helpers.tsindex b74afca093..3724d9cfc4 100644--- a/packages/dashboard/e2e/products-helpers.ts+++ b/packages/dashboard/e2e/products-helpers.ts@@ -107,6 +107,40 @@ function card(page: Page, title: RegExp): Locator {export const variantsCard = (page: Page) => card(page, /^Variants$/)export const mediaCard = (page: Page) => card(page, /^Media$/)++/**+ * Click a hover-revealed action on the first media thumbnail. Scrolls the+ * Media card below the sticky TopBar + PageHeader stack first — restoring+ * sticky headers (PR #14218) made Playwright's default scroll-into-view land+ * the bottom overlay buttons under the header chrome.+ */+export async function clickMediaThumbnailAction(+ media: Locator,+ action: 'edit' | 'delete',+): Promise<void> {+ const thumb = media.locator('img[src]').first()+ const button = media.getByRole('button', {+ name: action === 'edit' ? /^edit image$/i : /^delete image$/i,+ })++ await thumb.scrollIntoViewIfNeeded()+ // Keep the card below the stacked sticky TopBar + PageHeader. Playwright's+ // default click scrolls the target back into view, so we also force-click+ // after hover — otherwise the header chrome intercepts pointer events.+ await media.evaluate((el) => {+ const headerHeight =+ Number.parseFloat(+ getComputedStyle(document.documentElement).getPropertyValue('--spacing-header-height'),+ ) || 58+ const stickyOffset = headerHeight * 2 + 24+ const top = el.getBoundingClientRect().top+ if (top < stickyOffset) window.scrollBy(0, top - stickyOffset)+ })++ await thumb.hover()+ await expect(button).toBeVisible()+ await button.click({ force: true })+}export const customFieldsCard = (page: Page) => card(page, /^Custom fields$/)export const inventoryCard = (page: Page) => card(page, /^Inventory$/)export const pricesCard = (page: Page) => card(page, /^Prices$/)diff --git a/packages/dashboard/e2e/products-new-media.spec.ts b/packages/dashboard/e2e/products-new-media.spec.tsindex 858060cf9d..6957972aa7 100644--- a/packages/dashboard/e2e/products-new-media.spec.ts+++ b/packages/dashboard/e2e/products-new-media.spec.ts@@ -2,7 +2,7 @@ import * as path from 'node:path'import { fileURLToPath } from 'node:url'import { expect, test } from '@playwright/test'import { gotoIndex, login } from './helpers'-import { mediaCard, PRODUCTS_PATH } from './products-helpers'+import { clickMediaThumbnailAction, mediaCard, PRODUCTS_PATH } from './products-helpers'const FIXTURE_IMAGE = path.join(path.dirname(fileURLToPath(import.meta.url)),@@ -61,8 +61,7 @@ test.describe('new product — media', () => {await expect(media.locator('img[src]').first()).toBeVisible({ timeout: 15_000 })// Hover the thumb to reveal the delete button and click it.- await media.locator('img[src]').first().hover()- await media.getByRole('button', { name: /^delete image$/i }).click()+ await clickMediaThumbnailAction(media, 'delete')// Confirm the deletion in the dialog (handleDelete uses useConfirm now).await page.getByRole('dialog')diff --git a/packages/dashboard/src/components/spree/products/product-form-cards.tsx b/packages/dashboard/src/components/spree/products/product-form-cards.tsxindex d5e1ab8cac..32fb1d3d49 100644--- a/packages/dashboard/src/components/spree/products/product-form-cards.tsx+++ b/packages/dashboard/src/components/spree/products/product-form-cards.tsx@@ -337,7 +337,7 @@ export function MediaCard({return (<>- <Card>+ <Card className="scroll-mt-[calc(var(--spacing-header-height)*2+1.5rem)]"><CardHeader><CardTitle>{t('admin.pages.products.section_media')}</CardTitle></CardHeader>@@ -458,7 +458,7 @@ function SortableMediaThumbnail({src={previewUrl}alt={alt}draggable={false}- className="size-full object-cover transition-transform duration-300 ease-out group-hover:scale-105"+ className="pointer-events-none size-full object-cover"/>) : (<div className="flex size-full items-center justify-center text-muted-foreground">@@ -466,7 +466,7 @@ function SortableMediaThumbnail({</div>)}- <div className="pointer-events-none absolute inset-x-0 bottom-0 flex justify-end gap-1 p-1.5 opacity-0 translate-y-1 transition-all duration-200 ease-out group-hover:pointer-events-auto group-hover:opacity-100 group-hover:translate-y-0 group-focus-within:pointer-events-auto group-focus-within:opacity-100 group-focus-within:translate-y-0">+ <div className="pointer-events-none absolute inset-x-0 bottom-0 z-10 flex justify-end gap-1 p-1.5 opacity-0 translate-y-1 transition-all duration-200 ease-out group-hover:pointer-events-auto group-hover:opacity-100 group-hover:translate-y-0 group-focus-within:pointer-events-auto group-focus-within:opacity-100 group-focus-within:translate-y-0"><Buttontype="button"variant="outline"