Files
editor/e2e
SHAIK KHADEER BASHA 87fe93bc03 Keep the color picker within the viewport (#2398)
Fixes #717.

The color picker opened at a fixed offset next to its input
(`calcPickerOffset`), so near the bottom or right edge of the window
part of it was cut off. It now measures the panel after it opens and
places it on the inline-end side of the input (the right in LTR, the
left in RTL), switching sides only when there's no room, then clamps it
inside the viewport with an 8px margin. It repositions on resize and
scroll while open, and on very short windows the panel scrolls instead
of overflowing. The panel stays hidden for the first render until it has
a position, so it doesn't flash at the old spot.

| Before | After |
|---|---|
|
![before](https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-2398/before.png)
|
![after](https://raw.githubusercontent.com/KhadeerBasha1232/maputnik/pr-assets/pr-2398/after.png)
|

Both open the `background-color` picker with the field at the bottom of
a 1280px-wide window, in Chromium.

In the issue, orangemug suggested opening the picker inside the editor
panel instead of over the map. I kept the existing popover here because
that's a much smaller change and fixes the clipping on its own; moving
the picker into the panel would change the layout of every color field.

**Performance:** the resize and scroll listeners are only attached while
a picker is open and are removed when it closes or unmounts. Each event
does two `getBoundingClientRect` calls and only sets state when the
position actually changes.

## Launch Checklist

 - [x] Briefly describe the changes in this PR.
 - [x] Link to related issues: fixes #717.
- [x] Include before/after visuals or gifs if this PR includes visual
changes.
- [x] Write tests for all new functionality: two e2e tests in
`layer-editor.spec.ts`. One opens the picker with its field at the
bottom of the window and checks the whole picker is in the viewport; it
fails on `main`. The other switches to Hebrew and checks the picker
opens to the left of its field; it fails when I force the LTR side.
`shouldBeInViewport` in the helper now takes an optional ratio for the
first one.
 - [x] Add an entry to `CHANGELOG.md` under the `## main` section.

Tested locally: `npm run lint` clean, `npx tsc --noEmit` clean, `npx
vitest run` (57 passed) and `npx playwright test
e2e/layer-editor.spec.ts e2e/sprite-picker.spec.ts` (75 passed;
`sprite-picker` also uses `shouldBeInViewport`). The new test fails when
I run it against `main`. I didn't run the full e2e suite locally (it
times out on Windows with several workers); it passes in CI on this PR.

Assisted-By: Claude Opus 5.5 (Claude Code). It helped write the change,
the test and this description. I've reviewed and tested the change and
can answer questions about it.
2026-12-04 12:02:08 +02:00
..