fix(roadtrip): let the section filter shorten instead of overflowing

A nowrap label reports its whole width as its min-content contribution, so the
place-name select sat at its default `min-width: auto` and refused to shrink —
pushing the ± kilometres control past the panel's right edge instead of
ellipsing the name.

The menu that select opens now grows to its options rather than inheriting the
narrowed trigger, bounded by the panel it sits in so it never hangs over the
map: a list of identical shortened prefixes is not a list you can pick from.
This commit is contained in:
Maurice
2026-09-04 23:56:35 +02:00
committed by Maurice
parent 36ac5de84c
commit 620f4c6ecd
3 changed files with 94 additions and 8 deletions
@@ -104,6 +104,47 @@ describe('CustomSelect', () => {
expect(Number.parseInt(list.style.maxHeight, 10)).toBeGreaterThan(0);
});
// A select squeezed into a narrow flex row still has to offer readable options: the
// trigger shortens to share its row with the control beside it, the menu does not.
it('FE-COMP-SELECT-011: the menu is as wide as its trigger by default', async () => {
const user = userEvent.setup();
render(<CustomSelect value="" onChange={onChange} options={OPTIONS} />);
await user.click(screen.getByRole('button'));
const panel = screen.getByText('Apple').closest('div[style*="position: fixed"]') as HTMLElement;
expect(panel.style.width).not.toBe('max-content');
expect(panel.style.maxWidth).toBe('');
});
it('FE-COMP-SELECT-012: menuFit content grows the menu to its options, bounded twice', async () => {
const user = userEvent.setup();
render(<CustomSelect value="" onChange={onChange} options={OPTIONS} menuFit="content" />);
await user.click(screen.getByRole('button'));
const panel = screen.getByText('Apple').closest('div[style*="position: fixed"]') as HTMLElement;
expect(panel.style.width).toBe('max-content');
// Never narrower than the trigger, never wider than what the window still has.
expect(panel.style.minWidth).not.toBe('');
expect(Number.parseInt(panel.style.maxWidth, 10)).toBeGreaterThan(0);
});
it('FE-COMP-SELECT-013: a content-fitted menu stops at the edge of its panel', async () => {
const user = userEvent.setup();
render(
<div data-testid="panel">
<CustomSelect value="" onChange={onChange} options={OPTIONS} menuFit="content" />
</div>,
);
// jsdom measures everything as zero, so the panel says how wide it is.
const panel = screen.getByTestId('panel');
panel.getBoundingClientRect = () => ({ left: 0, right: 180, width: 180, top: 0, bottom: 32, height: 32, x: 0, y: 0, toJSON: () => ({}) }) as DOMRect;
await user.click(screen.getByRole('button'));
const menu = screen.getByText('Apple').closest('div[style*="position: fixed"]') as HTMLElement;
expect(menu.style.maxWidth).toBe('180px');
});
it('FE-COMP-SELECT-008: disabled state prevents the dropdown from opening', async () => {
const user = userEvent.setup();
render(<CustomSelect value="" onChange={onChange} options={OPTIONS} disabled={true} placeholder="Pick" />);