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.

Open the seeded option row and hide the placeholder variant

Damian Legawiec8bdae053671c
diff --git a/packages/dashboard/src/components/spree/products/variants-options-builder.tsx b/packages/dashboard/src/components/spree/products/variants-options-builder.tsx
index c1d73024a7..2d9330eee7 100644
--- a/packages/dashboard/src/components/spree/products/variants-options-builder.tsx
+++ b/packages/dashboard/src/components/spree/products/variants-options-builder.tsx
@@ -39,6 +39,14 @@ export function VariantsOptionsBuilder({ selected, onChange }: Props) {
const [editingIndex, setEditingIndex] = useState<number | null>(null)
const [isAdding, setIsAdding] = useState(false)
+ // A row with no values yet is one the merchant still has to act on — the
+ // product type seeds exactly that. Open the first one so the values picker
+ // is in front of them instead of hidden behind a click. Only while nothing
+ // else is being edited, so it never steals focus mid-interaction.
+ const firstEmptyIndex = selected.findIndex((optionType) => optionType.values.length === 0)
+ const expandedIndex =
+ editingIndex ?? (isAdding ? null : firstEmptyIndex >= 0 ? firstEmptyIndex : null)
+
const selectedIds = new Set(selected.map((s) => s.id))
const availableTypes = allOptionTypes.filter((ot) => !selectedIds.has(ot.id))
@@ -62,7 +70,7 @@ export function VariantsOptionsBuilder({ selected, onChange }: Props) {
<ul className="flex flex-col gap-2">
{selected.map((ot, i) => {
const optionType = allOptionTypes.find((t) => t.id === ot.id)
- const isEditing = editingIndex === i
+ const isEditing = expandedIndex === i
if (isEditing && optionType) {
return (
<li key={ot.id} className="rounded-lg border border-border p-3">
diff --git a/packages/dashboard/src/components/spree/products/variants-section.tsx b/packages/dashboard/src/components/spree/products/variants-section.tsx
index 5ad0fb71b4..4c3fc85759 100644
--- a/packages/dashboard/src/components/spree/products/variants-section.tsx
+++ b/packages/dashboard/src/components/spree/products/variants-section.tsx
@@ -187,6 +187,11 @@ export function VariantsSection({ form, seedFromType = false }: Props) {
const fields = variantsArray.fields
const hasOptionTypes = selected.length > 0
const isSimpleProduct = !hasOptionTypes && fields.length <= 1
+ // Options are being defined but none have values yet, so the only variant is
+ // the option-less placeholder. Showing it as "Default variant" next to a
+ // half-filled option row reads like a real row the merchant should edit.
+ const awaitingOptionValues =
+ hasOptionTypes && selected.every((optionType) => optionType.values.length === 0)
const handleOptionsChange = (next: SelectedOptionType[]) => {
// Keep the offered rows in step with the builder — including a removal,
@@ -353,7 +358,7 @@ export function VariantsSection({ form, seedFromType = false }: Props) {
</div>
)}
- {fields.length > 0 && (
+ {fields.length > 0 && !awaitingOptionValues && (
<div className="overflow-hidden rounded-md border border-border">
<DndContext
sensors={sensors}