AI-native design editor. Open-source Figma alternative.
fix(app): keep a bound number field's icon and value, and name its variable on hover (#1748)
Danila Poyarkov295f4d28f6f8
diff --git a/changes/1748/changed.md b/changes/1748/changed.mdnew file mode 100644index 000000000..4cad58cc5--- /dev/null+++ b/changes/1748/changed.md@@ -0,0 +1 @@+- A number field bound to a variable keeps its icon and shows its value; the variable button, now at the end of every field, names the variable on hover.diff --git a/src/components/inputs/NumberField.vue b/src/components/inputs/NumberField.vueindex 87cfee211..b1d09471c 100644--- a/src/components/inputs/NumberField.vue+++ b/src/components/inputs/NumberField.vue@@ -132,10 +132,7 @@ defineOptions({ inheritAttrs: false })actions.startScrub($event)">- <span- v-if="editing || !slots.bound || rootAttrs['data-bound'] === undefined"- :class="styles.leading({ class: ui?.leading })"- >+ <span :class="styles.leading({ class: ui?.leading })"><slot name="icon"><span v-if="icon" class="text-2xs leading-none">{{ icon }}</span></slot>diff --git a/src/components/properties/VariableNumberField.vue b/src/components/properties/VariableNumberField.vueindex ac7fba322..1bcfa88f9 100644--- a/src/components/properties/VariableNumberField.vue+++ b/src/components/properties/VariableNumberField.vue@@ -67,11 +67,6 @@ const accessibleLabel = computed(() => {})const bindingStyles = useBindingFieldUI()-function bindingTooltip(name: string, resolvedValue: unknown) {- if (typeof resolvedValue !== 'number') return name- return `${name} · ${resolvedValue}${suffix ?? ''}`-}-defineOptions({ inheritAttrs: false })</script>@@ -109,19 +104,20 @@ defineOptions({ inheritAttrs: false })<template v-if="$slots.display" #display="display"><slot name="display" v-bind="display" /></template>- <template v-if="binding.variable || binding.state === 'unresolved'" #bound>+ <!-- A bound number reads like any other, its variable named by the variable button's+ tooltip; with no value to show, an unresolved binding names its variable. -->+ <template v-if="binding.state === 'unresolved'" #bound><BindingPill- :unresolved="binding.state === 'unresolved'"+ unresolved:label="binding.variable?.name ?? binding.bindingId ?? panels.unresolvedVariable"- :tooltip="- binding.state === 'unresolved'- ? panels.unresolvedVariable- : bindingTooltip(binding.variable?.name ?? '', binding.resolvedValue)- "+ :tooltip="panels.unresolvedVariable"/></template><template #suffix>- <span :class="$slots['after-variable'] ? '' : 'pr-1'" class="flex items-center">+ <!-- A field's own control, such as Hug or a mode menu, sits beside its value; the variable+ button ends every field, so it lines up down the panel. -->+ <slot name="after-variable" />+ <span class="flex items-center pr-1"><VariableBindingPicker:trigger-label="panels.applyVariable":search-placeholder="common.search"@@ -136,7 +132,6 @@ defineOptions({ inheritAttrs: false }):create-submit-label="panels.create"/></span>- <slot name="after-variable" /></template></NumberField></BindableValueRoot>diff --git a/src/components/ui/binding/VariablePicker.vue b/src/components/ui/binding/VariablePicker.vueindex 0d20363da..710c7d372 100644--- a/src/components/ui/binding/VariablePicker.vue+++ b/src/components/ui/binding/VariablePicker.vue@@ -47,6 +47,11 @@ const createName = ref('')const createInput = ref<HTMLInputElement | null>(null)const canCreate = computed(() => createName.value.trim().length > 0)const styles = computed(() => useBindingFieldUI({ state, open: open.value, disabled, derived }, ui))+/** Hovering the variable button of a bound value names its variable. */+const triggerTooltip = computed(() => {+ const bound = state === 'bound' ? items.find((item) => item.id === selected) : undefined+ return bound?.name ?? triggerLabel+})const pickerItems = computed<AppPickerItem[]>(() =>items.map((item) => ({ value: item.id, label: item.name, group: item.collection })))@@ -92,7 +97,7 @@ defineOptions({ inheritAttrs: false }):search-placeholder="searchPlaceholder":empty-label="emptyLabel":close-label="closeLabel ?? common.close"- :tooltip="triggerLabel"+ :tooltip="triggerTooltip":side="side"@select="emit('select', $event)"@close-auto-focus="emit('closeAutoFocus', $event)"diff --git a/tests/e2e/properties/corner/bindings.spec.ts b/tests/e2e/properties/corner/bindings.spec.tsindex f7ab73e5d..cbfe29068 100644--- a/tests/e2e/properties/corner/bindings.spec.ts+++ b/tests/e2e/properties/corner/bindings.spec.ts@@ -41,7 +41,12 @@ test('collapsed equivalent corners preserve their shared token through expansion})const section = propertySection(page, 'Appearance')const field = propertyField(page, 'cornerRadius')- await expect(field.getByText('Radius/shared', { exact: true })).toBeVisible()+ await expect(field).toHaveAttribute('data-bound')+ // A bound number shows its value; hovering the variable button names the variable.+ await expect(field).toContainText('12')+ await field.getByRole('button', { name: 'Apply variable' }).hover()+ await expect(page.getByRole('tooltip')).toHaveText('Radius/shared')+ await page.mouse.move(0, 0)if (process.platform === 'darwin') {await expect(section).toHaveScreenshot('shared-corner-token.png')}@@ -62,13 +67,12 @@ test('collapsed equivalent corners preserve their shared token through expansionconst toggle = section.getByRole('button', { name: 'Independent corner radii' })await toggle.click()for (const path of paths) {- await expect(- propertyField(page, path).getByText('Radius/shared', { exact: true })- ).toBeVisible()+ await expect(propertyField(page, path)).toHaveAttribute('data-bound')+ await expect(propertyField(page, path)).toContainText('12')}expect(await readCorners()).toEqual(original)await toggle.click()- await expect(field.getByText('Radius/shared', { exact: true })).toBeVisible()+ await expect(field).toHaveAttribute('data-bound')await field.click({ position: { x: 40, y: 13 } })const input = field.getByRole('spinbutton', { name: 'Radius', exact: true })await expect(input).toHaveValue('12')@@ -77,7 +81,7 @@ test('collapsed equivalent corners preserve their shared token through expansionawait field.click({ position: { x: 40, y: 13 } })await input.fill('18')await input.press('Escape')- await expect(field.getByText('Radius/shared', { exact: true })).toBeVisible()+ await expect(field).toHaveAttribute('data-bound')expect(await readCorners()).toEqual(original)await field.click({ position: { x: 40, y: 13 } })await input.fill('24')@@ -88,7 +92,7 @@ test('collapsed equivalent corners preserve their shared token through expansionindependent: false})await canvas.pressKey('Meta+z')- await expect(field.getByText('Radius/shared', { exact: true })).toBeVisible()+ await expect(field).toHaveAttribute('data-bound')expect(await readCorners()).toEqual(original)await canvas.pressKey('Meta+Shift+z')expect(await readCorners()).toEqual({diff --git a/tests/e2e/properties/corner/bindings.spec.ts-snapshots/shared-corner-token-openpencil-darwin.png b/tests/e2e/properties/corner/bindings.spec.ts-snapshots/shared-corner-token-openpencil-darwin.pngindex 304ad59c1..fbfdb1634 100644Binary files a/tests/e2e/properties/corner/bindings.spec.ts-snapshots/shared-corner-token-openpencil-darwin.png and b/tests/e2e/properties/corner/bindings.spec.ts-snapshots/shared-corner-token-openpencil-darwin.png differdiff --git a/tests/e2e/properties/dimensions.spec.ts-snapshots/dimensions-bound-light-openpencil-darwin.png b/tests/e2e/properties/dimensions.spec.ts-snapshots/dimensions-bound-light-openpencil-darwin.pngindex 0cd63927c..d681e6ae8 100644Binary files a/tests/e2e/properties/dimensions.spec.ts-snapshots/dimensions-bound-light-openpencil-darwin.png and b/tests/e2e/properties/dimensions.spec.ts-snapshots/dimensions-bound-light-openpencil-darwin.png differdiff --git a/tests/e2e/properties/panel/controls.spec.ts b/tests/e2e/properties/panel/controls.spec.tsindex 178050b4f..ae86e56cd 100644--- a/tests/e2e/properties/panel/controls.spec.ts+++ b/tests/e2e/properties/panel/controls.spec.ts@@ -417,7 +417,7 @@ test('width can create, bind, and detach a number variable', async () => {await editor.page.getByRole('button', { name: 'Create', exact: true }).click()await editor.canvas.waitForRender()- await expect(widthField.getByText('Card/width')).toBeVisible()+ await expect(widthField).toHaveAttribute('data-bound')const boundVariable = await editor.page.evaluate(() => {const store = window.openPencil?.getStore?.()if (!store) throw new Error('OpenPencil store not initialized')@@ -435,7 +435,7 @@ test('width can create, bind, and detach a number variable', async () => {await widthInput.press('Enter')await editor.canvas.waitForRender()- await expect(widthField.getByText('Card/width')).toHaveCount(0)+ await expect(widthField).not.toHaveAttribute('data-bound')const directWidth = await editor.page.evaluate(() => {const store = window.openPencil?.getStore?.()if (!store) throw new Error('OpenPencil store not initialized')@@ -457,7 +457,7 @@ test('bound NumberField detach edit is one undo step', async () => {await editor.page.getByPlaceholder('Variable name').fill('Radius/default')await editor.page.getByRole('button', { name: 'Create', exact: true }).click()await editor.canvas.waitForRender()- await expect(field.getByText('Radius/default')).toBeVisible()+ await expect(field).toHaveAttribute('data-bound')const readState = () =>editor.page.evaluate(() => {diff --git a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.png b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.pngindex 9c666314d..b3d53fd34 100644Binary files a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.png and b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.png differdiff --git a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.png b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.pngindex 25ad84119..10267d2d4 100644Binary files a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.png and b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.png differdiff --git a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.png b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.pngindex d6ed4910a..e0a91d397 100644Binary files a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.png and b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.png differdiff --git a/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-dark-openpencil-darwin.png b/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-dark-openpencil-darwin.pngindex 114f3f726..e67dc3f7f 100644Binary files a/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-dark-openpencil-darwin.png and b/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-dark-openpencil-darwin.png differdiff --git a/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-light-openpencil-darwin.png b/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-light-openpencil-darwin.pngindex 26e6badbd..415992de6 100644Binary files a/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-light-openpencil-darwin.png and b/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-light-openpencil-darwin.png differdiff --git a/tests/e2e/properties/unresolved-binding.spec.ts b/tests/e2e/properties/unresolved-binding.spec.tsindex 18b529309..1a239112a 100644--- a/tests/e2e/properties/unresolved-binding.spec.ts+++ b/tests/e2e/properties/unresolved-binding.spec.ts@@ -102,8 +102,10 @@ for (const theme of ['light', 'dark']) {await expect(field.locator('[data-slot="pill"]')).toHaveAttribute('data-unresolved')await field.getByRole('button', { name: 'Apply variable' }).click()await page.getByRole('option', { name: 'Tracking/Replacement' }).click()- await expect(field).toContainText('Tracking/Replacement')- await expect(field.locator('[data-slot="pill"]')).not.toHaveAttribute('data-unresolved')+ // A resolved number shows its value, so the unresolved pill is gone.+ await expect(field).toHaveAttribute('data-bound')+ await expect(field).toContainText('6')+ await expect(field.locator('[data-slot="pill"]')).toHaveCount(0)})})}