Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fix: grid cells keep a value left by clicking elsewhere (#14729)

Damian Legawiec61f902f57228
diff --git a/.changeset/dashboard-ui-grid-click-away.md b/.changeset/dashboard-ui-grid-click-away.md
new file mode 100644
index 0000000000..e65ae11404
--- /dev/null
+++ b/.changeset/dashboard-ui-grid-click-away.md
@@ -0,0 +1,5 @@
+---
+"@spree/dashboard-ui": patch
+---
+
+A spreadsheet cell being edited now keeps its value when you leave it by clicking somewhere else, the same as leaving it with Tab or Enter. Before, a price, compare-at price or stock count typed on the product form was dropped when you clicked into another field or pressed Save.
diff --git a/packages/dashboard-ui/src/spree/data-grid/data-grid.tsx b/packages/dashboard-ui/src/spree/data-grid/data-grid.tsx
index 98b3ee1804..a123c18b98 100644
--- a/packages/dashboard-ui/src/spree/data-grid/data-grid.tsx
+++ b/packages/dashboard-ui/src/spree/data-grid/data-grid.tsx
@@ -241,7 +241,11 @@ function DataGridShell<T>({
className,
)}
aria-label={ariaLabel}
- onBlurCapture={(e) => {
+ // Bubble phase, never capture: React dispatches the two phases from
+ // separate native listeners and renders queued updates between
+ // them, so clearing `editing` here first would re-render the cell
+ // out of edit mode before its own blur commits the typed value.
+ onBlur={(e) => {
// A cell unmounting mid-commit is not the merchant leaving the
// grid: `relatedTarget` is null there, and the dialog's focus
// trap then claims the focus a frame later. Take it back on the
diff --git a/packages/dashboard/e2e/products-prices-inventory.spec.ts b/packages/dashboard/e2e/products-prices-inventory.spec.ts
index 4f93c76e63..cb72809527 100644
--- a/packages/dashboard/e2e/products-prices-inventory.spec.ts
+++ b/packages/dashboard/e2e/products-prices-inventory.spec.ts
@@ -115,6 +115,43 @@ test.describe('product prices — single variant', () => {
).toHaveValue(/^12[.,]50?$/)
})
+ // `fillGridCell` leaves a cell with a scripted `blur()`. A merchant leaves it
+ // by clicking somewhere else, which the browser dispatches differently — and
+ // that path used to drop the value the cell was showing.
+ test('keeps price and stock edits left by clicking elsewhere', async ({ page }) => {
+ const creds = await login(page)
+
+ const productName = `E2E Click Away ${Date.now()}`
+ await createProduct(page, creds.store_id, productName)
+
+ const price = pricesCard(page).getByRole('textbox', { name: /^price for default$/i })
+ await price.dblclick()
+ await price.fill('19.99')
+ await page.getByLabel(/^name$/i).click()
+ await expect(price).toHaveValue(/^19[.,]99$/)
+
+ const onHand = inventoryCard(page)
+ .getByRole('textbox', { name: /^on hand at /i })
+ .first()
+ await onHand.dblclick()
+ await onHand.fill('12')
+ // Still in edit mode when Save is clicked.
+ await page.getByRole('button', { name: /save product/i }).click()
+ await expect(page.getByRole('button', { name: /save product/i })).toBeDisabled({
+ timeout: 30_000,
+ })
+
+ await page.reload()
+ await expect(
+ pricesCard(page).getByRole('textbox', { name: /^price for default$/i }),
+ ).toHaveValue(/^19[.,]99$/)
+ await expect(
+ inventoryCard(page)
+ .getByRole('textbox', { name: /^on hand at /i })
+ .first(),
+ ).toHaveValue('12')
+ })
+
// Multi-currency + localized. The inline Prices card switches currency via
// its header selector; each currency's prices ride the SAME product PATCH.
// Enter a USD price (period) and a EUR price comma-decimal (`34,56`), save