From b8020ceae3e5b5ad699990f83b0ffd9eba2549eb Mon Sep 17 00:00:00 2001 From: SHAIK KHADEER BASHA <120262074+KhadeerBasha1232@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:43:09 +0530 Subject: [PATCH] Edit icon-padding as a list of one to four numbers (#2391) Fixes #950. `icon-padding` is the only property with the `padding` type, which takes one to four numbers. The editor rendered it as a fixed four-box `InputArray`, so: - an unset or single-value padding showed one number and three empty boxes, which is the "extra empty fields" from the last comment on the issue; - `InputArray` only calls `onChange` once every box is filled, so typing one, two or three values never reached the style. Now `padding` shares the `numberArray` case and uses `InputDynamicArray`, the same add/remove list as `hillshade-illumination-direction`. `InputDynamicArray` gets an optional `maxLength`, which hides "Add value" once there are four padding values. Nothing else passes `maxLength`, so the other array fields don't change. An unset `icon-padding` now shows one empty box, like other unset number arrays, instead of the default `2` as a placeholder. | Before | After | |---|---| | ![before](https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-950/before-icon-padding.png) | ![after](https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-950/after-icon-padding.png) | Both screenshots show the `icon-padding` field of a new symbol layer in Chromium. **Performance:** none. It's the component other array properties already use, and only `icon-padding` renders it here. ## Launch Checklist - [x] Briefly describe the changes in this PR. - [x] Link to related issues. - [x] Include before/after visuals or gifs if this PR includes visual changes. - [x] Write tests for all new functionality: two e2e tests in `layers-list.spec.ts`. "should save a single icon-padding value" fails on `main`, and fails when I change the expected `[5]` to `[7]`. "should not offer a fifth icon-padding value" fails without the `maxLength` cap. - [x] Add an entry to `CHANGELOG.md` under the `## main` section. Tested locally: `npm run lint` clean, `npx tsc --noEmit` clean, `npx vitest run` (55 passed), `npx playwright test e2e/layers-list.spec.ts` (44 passed), and the full `npx playwright test` before adding the cap (everything passes; with 4 workers 19 tests in the modal, history and accessibility specs timed out on my machine, and all 19 pass when rerun with `--workers=1`). Assisted-By: Claude Opus 5.5 (Claude Code). It helped write the fix, the tests and this description. I've reviewed and tested the change and can answer questions about it. --- CHANGELOG.md | 1 + e2e/layers-list.spec.ts | 21 +++++++++++++++++++++ e2e/maputnik-driver.ts | 2 ++ src/components/InputDynamicArray.tsx | 16 ++++++++++------ src/components/InputSpec.tsx | 13 ++++--------- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66a80171..a77e7f1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - _...Add new stuff here..._ ### 🐞 Bug fixes +- Fix `icon-padding` showing four inputs and only saving once all four were filled; it now uses the same add/remove list as other number arrays, up to four values - Make small sprites easier to recognize in the sprite picker with fixed-size previews and high-resolution sprite assets - Prevent a crash when converting a function to an expression - Prevent a crash when deleting either stop from a function with two stops diff --git a/e2e/layers-list.spec.ts b/e2e/layers-list.spec.ts index 2cc4bccb..1e3415f2 100644 --- a/e2e/layers-list.spec.ts +++ b/e2e/layers-list.spec.ts @@ -207,6 +207,27 @@ describe("layers list", () => { await when.click("field-doc-button-Rotate", 0); await then(get.elementByTestId("spec-field-doc")).shouldNotBeVisible(); }); + + test("should save a single icon-padding value", async () => { + const id = await when.modal.fillLayers({ type: "symbol", layer: "example" }); + + await when.setValueToPropertyArray("spec-field:icon-padding", "5"); + + await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({ + layers: [{ id, layout: { "icon-padding": [5] } }], + }); + }); + + test("should not offer a fifth icon-padding value", async () => { + await when.modal.fillLayers({ type: "symbol", layer: "example" }); + + await when.setValueToPropertyArray("spec-field:icon-padding", "1"); + await when.addValueToPropertyArray("spec-field:icon-padding", "2"); + await when.addValueToPropertyArray("spec-field:icon-padding", "3"); + await when.addValueToPropertyArray("spec-field:icon-padding", "4"); + + await then(get.propertyArrayAddButton("spec-field:icon-padding")).shouldNotExist(); + }); }); describe("raster", () => { diff --git a/e2e/maputnik-driver.ts b/e2e/maputnik-driver.ts index 2deca7e0..c21687d3 100644 --- a/e2e/maputnik-driver.ts +++ b/e2e/maputnik-driver.ts @@ -416,6 +416,8 @@ export class MaputnikDriver { jsonEditorErrors: (selector: string) => this.helper.get.elementByTestId(selector).locator(".cm-lint-marker-error"), + propertyArrayAddButton: (selector: string) => this.helper.get.elementByTestId(selector).locator(".maputnik-array-add-value"), + styleFromLocalStorage: () => this.helper.query(() => this.readStoredStyle()), fixture: (name: string) => this.helper.readFixture(name), diff --git a/src/components/InputDynamicArray.tsx b/src/components/InputDynamicArray.tsx index fb860ca4..1dc88960 100644 --- a/src/components/InputDynamicArray.tsx +++ b/src/components/InputDynamicArray.tsx @@ -16,6 +16,8 @@ export type InputDynamicArrayProps = { value?: (string | number | undefined)[] type?: "url" | "number" | "enum" | "string" | "color" default?: (string | number | undefined)[] + /** Hide the "Add value" button once the array has this many values */ + maxLength?: number onChange?(values: (string | number | undefined)[] | undefined): unknown style?: object fieldSpec?: { @@ -130,12 +132,14 @@ class InputDynamicArrayInternal extends React.Component {inputs} - - {t("Add value")} - + {(this.props.maxLength === undefined || this.values.length < this.props.maxLength) && + + {t("Add value")} + + } ); } diff --git a/src/components/InputSpec.tsx b/src/components/InputSpec.tsx index 4f7a13e7..0b1bb943 100644 --- a/src/components/InputSpec.tsx +++ b/src/components/InputSpec.tsx @@ -110,12 +110,15 @@ export class InputSpec extends React.Component { />; } } - case "numberArray": return ( + case "numberArray": + case "padding": return ( ); case "colorArray": return ( @@ -126,14 +129,6 @@ export class InputSpec extends React.Component { value={(Array.isArray(this.props.value) ? this.props.value : [this.props.value]) as (string | number | undefined)[]} /> ); - case "padding": return ( - - ); default: console.warn(`No proper field input for ${this.props.fieldName} type: ${this.props.fieldSpec?.type}`); return null;