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: Escape in a multi-select picker removed every chosen item (#14778)
Łukasz Adamczyk3a2a78bb43f8
diff --git a/.changeset/escape-keeps-multi-select-choices.md b/.changeset/escape-keeps-multi-select-choices.mdnew file mode 100644index 0000000000..02f41ca539--- /dev/null+++ b/.changeset/escape-keeps-multi-select-choices.md@@ -0,0 +1,5 @@+---+"@spree/dashboard-ui": patch+---++Fixed pressing Escape in a multi-select picker removing every chosen item. After searching and picking a category, the Escape meant to close the search emptied the whole field, and saving the product then stored no categories. Escape no longer removes chosen items, which are removed with their own remove button or Backspace; with the list already closed, it closes the surrounding sheet or dialog instead.diff --git a/packages/dashboard-ui/src/ui/combobox.tsx b/packages/dashboard-ui/src/ui/combobox.tsxindex 070b51dca2..dda281afb4 100644--- a/packages/dashboard-ui/src/ui/combobox.tsx+++ b/packages/dashboard-ui/src/ui/combobox.tsx@@ -8,7 +8,33 @@ import { CheckIcon, ChevronDownIcon, XIcon } from '../spree/icons'import { Button } from './button'import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from './input-group'-const Combobox = ComboboxPrimitive.Root+/**+ * Base UI empties a multi-select when Escape is pressed with its popup closed,+ * and picking a searched result closes the popup, so the Escape meant to+ * dismiss the search silently wiped every chip. Chips are removed only through+ * their own remove button or Backspace, and the Escape passes on to whatever+ * encloses the picker, such as a sheet, as it does for an empty one.+ */+function Combobox<Value, Multiple extends boolean | undefined = false, Item = Value>(+ props: ComboboxPrimitive.Root.Props<Value, Multiple, Item>,+) {+ const { multiple, onValueChange } = props+ if (!multiple) return <ComboboxPrimitive.Root {...props} />++ return (+ <ComboboxPrimitive.Root+ {...props}+ onValueChange={(value, eventDetails) => {+ if (eventDetails.reason === 'escape-key') {+ eventDetails.cancel()+ eventDetails.allowPropagation()+ return+ }+ onValueChange?.(value, eventDetails)+ }}+ />+ )+}function ComboboxValue({ ...props }: ComboboxPrimitive.Value.Props) {return <ComboboxPrimitive.Value data-slot="combobox-value" {...props} />diff --git a/packages/dashboard/e2e/product-types.spec.ts b/packages/dashboard/e2e/product-types.spec.tsindex eefb7d012f..15fb766fe5 100644--- a/packages/dashboard/e2e/product-types.spec.ts+++ b/packages/dashboard/e2e/product-types.spec.ts@@ -1,5 +1,5 @@import { expect, test } from '@playwright/test'-import { gotoIndex, login } from './helpers'+import { FIXTURE_PROMO_TAXON, gotoIndex, login } from './helpers'const PATH = (storeId: string) => `/${storeId}/settings/product-types`const CTA = /add product type/i@@ -25,6 +25,32 @@ test.describe('product types', () => {await expect(page.getByText(name)).toBeVisible({ timeout: 15_000 })})+ test('closes the sheet on Escape from a category picker holding a choice', async ({ page }) => {+ const creds = await login(page)+ await gotoIndex(page, PATH(creds.store_id), CTA)++ await page.getByRole('button', { name: CTA }).click()+ const heading = page.getByRole('heading', { name: /new product type/i })+ await expect(heading).toBeVisible()++ const categoriesField = page+ .getByRole('dialog')+ .locator('[data-slot="field"]')+ .filter({ has: page.getByText('Categories', { exact: true }) })+ const search = categoriesField.getByRole('combobox')+ await search.fill(FIXTURE_PROMO_TAXON)+ await page+ .getByRole('option', { name: new RegExp(FIXTURE_PROMO_TAXON, 'i') })+ .first()+ .click()+ await expect(categoriesField.locator('[data-slot="combobox-chip"]')).toHaveCount(1)+ await expect(page.getByRole('listbox')).toBeHidden()+ await expect(search).toBeFocused()++ await page.keyboard.press('Escape')+ await expect(heading).toBeHidden()+ })+test('rejects a product type with no name', async ({ page }) => {const creds = await login(page)await gotoIndex(page, PATH(creds.store_id), CTA)diff --git a/packages/dashboard/e2e/products-edit.spec.ts b/packages/dashboard/e2e/products-edit.spec.tsindex b3a1a45a6b..59df9caa4b 100644--- a/packages/dashboard/e2e/products-edit.spec.ts+++ b/packages/dashboard/e2e/products-edit.spec.ts@@ -1,5 +1,10 @@import { expect, test } from '@playwright/test'-import { FIXTURE_BULK_CHANNEL_NAME, login } from './helpers'+import {+ FIXTURE_BULK_CATEGORY,+ FIXTURE_BULK_CHANNEL_NAME,+ FIXTURE_PROMO_TAXON,+ login,+} from './helpers'import { createProduct, publishingCard, typeDescription } from './products-helpers'test.describe('product edit', () => {@@ -128,6 +133,39 @@ test.describe('product edit', () => {await expect(page.getByLabel(/^name$/i)).toHaveValue(updated)})+ test('keeps picked categories when Escape dismisses the search', async ({ page }) => {+ const creds = await login(page)+ await createProduct(page, creds.store_id, `E2E Product Categories ${Date.now()}`)++ const categoriesField = page+ .locator('[data-slot="field"]')+ .filter({ has: page.getByText('Categories', { exact: true }) })+ const search = categoriesField.getByRole('combobox')+ const chips = categoriesField.locator('[data-slot="combobox-chip"]')++ // Picking a searched result closes the list, so the Escape that follows+ // lands on a closed picker.+ for (const category of [FIXTURE_PROMO_TAXON, FIXTURE_BULK_CATEGORY]) {+ await search.fill(category)+ await page+ .getByRole('option', { name: new RegExp(category, 'i') })+ .first()+ .click()+ }+ await expect(chips).toHaveCount(2)+ await expect(page.getByRole('listbox')).toBeHidden()+ await expect(search).toBeFocused()+ await page.keyboard.press('Escape')+ await expect(chips).toHaveCount(2)++ await page.getByRole('button', { name: /save product/i }).click()+ await expect(page.getByRole('button', { name: /save product/i })).toBeDisabled({+ timeout: 15_000,+ })+ await page.reload()+ await expect(chips).toHaveCount(2)+ })+test('lists a product on an additional channel via the publishing card', async ({ page }) => {const creds = await login(page)const name = `E2E Product Publish ${Date.now()}`