← Examples Gallery

Placement Demo

Alap uses a compass-based placement engine with three strategy levels. The placement attribute is a comma-separated string: compass direction + strategy.

Placement Strategies

The placement attribute takes a compass direction and an optional strategy, separated by a comma:

AttributeWhat happens
placement="SE"Position SE. If it doesn't fit, try fallbacks. Default strategy (flip).
placement="SE, clamp"Flip + constrain to viewport. Overrides min-width, scrolls long menus.
placement="SE, place"Pinned at SE. No fallback, no clamping.
(not set)Engine doesn't run. CSS positions the menu.

1. DOM Adapter — Compass Rose

Each link requests a specific direction with the default flip strategy. Trigger centered — every placement fits.

NW
N
NE
W
C
E
SW
S
SE

2. Web Component — Compass Rose

Same compass grid using <alap-link> with the placement attribute.

NW
N
NE
W
C
E
SW
S
SE

3. Inline Text — Natural Flow

Placement works with inline text. Here the menu opens above (N), below (S), beside (E), or centered (C) over the trigger word. Here's a long menu inline with 20 items (clamped) that should clamp without scrolling the page.

Stress Tests

Edge cases that exercise the fallback and clamping logic. Each test has a scroll to position link that puts the trigger at the viewport edge so you can see the fallback in action.

4. Horizontal Edge Flips

Links at the viewport edges. E on the right should flip to W; W on the left should flip to E.

Scroll to test position ↓

W ← wants left, no room wants right, no room → E

Same test with the web component:

W ← should flip E should flip W → E

5. Vertical Edge Flips — Top of Viewport

These links want to go above, but there's no room. Scroll so the row is at the very top of the viewport, then click.

Scroll to test position ↓

N ↑ no room above  —  NW no room above  —  NE no room above

6. Corner Stress Tests

Links pinned to each corner. Every placement requested is the worst possible for that corner. Using clamp strategy to constrain to viewport.

Scroll to test position ↓

NW in top-left NE in top-right SW in bottom-left SE in bottom-right

7. Long Menu — Height Clamping

20 items with clamp strategy. The menu can't fit fully — it should clamp to available space and scroll internally. No page scroll.

Scroll to test position ↓

SE, clamp

20 items

N, clamp

20 items

C, clamp

20 items

E, clamp

20 items

Same links with flip (default) — no clamping, menu may overflow:

SE (flip)

20 items

N (flip)

20 items

8. Long Menu Near Bottom of Viewport

A long menu near the bottom with clamp. SE overflows massively — should flip above or clamp. Scroll so the links are near the bottom of your viewport, then click.

Scroll to test position ↓ — the links should be near the bottom of your viewport after scrolling.

20 items, SE clamp  —  20 items, S clamp  —  20 items, SE clamp (WC)  —  20 items, C clamp

9. Right Edge — Forced Flips

Links pinned flush against the right viewport edge. SE and E have no room to the right. Using clamp to constrain wide menus.

Scroll to test position ↓

SE flush right (clamp) E flush right, 20 items (clamp) NE flush right (clamp) E flush right, 20 items (WC, clamp)