002 Cascade Menu
계단식 메뉴의 안전 영역과 지연
계단식 메뉴의 삼각형 안전 영역과 세 가지 지연으로, 포인터를 하위 메뉴 쪽으로 비스듬히 움직여도 하위 메뉴가 잘못 바뀌거나 갑자기 닫히지 않게 합니다.
포인터를 상위 메뉴에서 하위 메뉴로 비스듬히 옮기면 아래쪽 몇 줄을 지나가게 됩니다. 일반 메뉴는 지나가는 줄마다 그 줄로 전환되어 하위 메뉴가 사라지고, 사용자는 되돌아가 다시 열어야 합니다. 해결 방법은 다음 네 가지입니다.
- 삼각형 안전 영역: 하위 메뉴가 열려 있고 포인터가 그쪽으로 움직이고 있을 때 씁니다. 직전 포인터 위치를 꼭짓점으로 삼아 하위 메뉴 가까운 쪽의 위아래 두 모서리와 이어 삼각형을 만듭니다. 포인터가 삼각형 안에 있으면 지나가는 줄을 강조하지 않고 그 줄의 하위 메뉴도 열지 않으며, 삼각형을 벗어나야 현재 줄로 전환합니다.
- 전환 지연: 포인터가 삼각형 안의 어떤 줄에 멈춰 있다면 사용자가 그 줄을 고르려는 것입니다. 1.2초 넘게 머무르면 메뉴를 그 줄로 전환해, 하위 메뉴가 계속 바뀌지 않는 일이 없게 합니다.
- 열기 지연: 포인터가 메뉴 한 열을 빠르게 훑고 지나갈 때를 위한 것입니다. 220ms 동안 호버한 뒤에 하위 메뉴를 열고 그 전에 벗어나면 취소하므로, 하위 메뉴가 줄줄이 열리지 않습니다. 터치스크린에서 탭하면 바로 적용됩니다.
- 닫기 지연: 포인터가 메뉴 가장자리 밖으로 살짝 벗어날 때를 위한 것입니다. 메뉴를 벗어나고 360ms가 지나야 닫고, 그 안에 돌아오면 그대로 둡니다. 메뉴 바깥을 클릭하면 바로 닫습니다.
또한 줄의 강조는 컴포넌트 상태로 제어하고 CSS의 :hover는 쓰지 않습니다. 그렇지 않으면 메뉴가 전환되지 않았는데도 삼각형 안에서 지나간 줄이 강조됩니다.
함께 제공하는 Prompt는 이 규칙을 프로젝트의 기존 메뉴 컴포넌트에 추가하고, 기존 인터페이스와 키보드 조작은 그대로 유지합니다. 메뉴 컴포넌트가 없을 때만 새로 만듭니다.
Define a cascading (nested) menu component that keeps its submenus steady:
a safe zone plus three delays, so submenus open on purpose, survive diagonal
moves toward them, and do not vanish on a brief slip out of the menu.
If the project already has a menu or dropdown component, build this into
its existing submenu logic and keep its API, keyboard support and
accessibility as they are. Otherwise create one reusable CascadeMenu:
- Props: an anchor (the trigger button that opens it on click) and a tree
of items, each { label, icon?, href?, children? }. An item with children
is a folder row; one without is a plain row that navigates on click.
- Each level shows its folder's name as a small title above its rows.
- Keyboard: arrow keys move through rows, Right/Enter opens a folder,
Left goes back a level, Escape closes everything and returns focus to
the anchor. Use menu / menuitem roles and aria-expanded on folder rows.
Behavior, with the values to use:
1. Open delay: hovering a row schedules it to take effect after 220ms: a
folder row opens its submenu, a plain row closes any deeper submenu.
Leaving the row before then cancels it. Touch input acts at once.
2. Safe zone: while a submenu is open, build a triangle from the pointer's
previous position to the two corners of the submenu's near edge (the
left edge's top and bottom for a submenu on the right). Track the last
two pointermove positions and use the older one as the apex, so the
triangle never collapses onto the current point. If the pointer is
inside that triangle and within the parent's last
min(90px, max(56px, 43% of the parent width)) toward the submenu, it is
on its way there: rows it crosses must not highlight or open their own
submenus.
3. Safe window: a row hovered inside the safe zone does not switch the
submenu right away. Recheck every 80ms; switch once the pointer leaves
the zone, or when 1200ms have passed since the hover began, so a
pointer that simply stops there still gets its new submenu.
4. Close delay: when the pointer leaves the anchor, every open level and
the safe zone, close the whole menu after 360ms. Coming back in time
cancels the close. Clicking outside closes at once.
5. Dragging an item over a folder row opens it after 420ms instead of 220ms.
6. The pointer inside an open submenu ends all protection.
Drive row highlight from component state (hovered, active, skipped), not
from CSS :hover, or rows crossed inside the safe zone will still light up.
Geometry and motion:
- Submenus open to the right, overlap their parent by 8px and align their
first row with the parent row. Flip to the left when there is no room;
the safe zone then uses the submenu's right edge.
- Levels: 210-260px wide, sized to content, max height
min(420px, 100vh - 24px) with their own scroll, 6px padding, 12px radius,
1px border, backdrop-filter blur(18px) saturate(135%).
- Rows: 32px tall, 8px radius, 4px apart, 0 8px padding, 8px gap; 18px
icon, 14px weight-500 label, a 16px chevron on folder rows. Level title:
11px, weight 600, quiet ink, padding 4px 8px 2px.
- A submenu opens from its parent's edge: from translateX(-8px)
scale(0.88, 0.98) and opacity 0, with opacity over 170ms and transform
over 360ms on cubic-bezier(0.2, 1.45, 0.35, 1).
- The root level opens the same way from its anchor: from translateY(-6px)
scale(0.96, 0.86), top-left origin. Keep the overshoot curve: the slight
spring is part of the feel.
- A folder row's icon turns from a closed folder into an open one while its
submenu is open, and back when it closes, over 460ms on
cubic-bezier(0.22, 1, 0.36, 1). Morph the paths if the two glyphs share
their structure; otherwise cross-fade them with a slight lift of the
front panel.
Light and dark themes come from tokens, not separate components:
- Light: surface rgba(255,255,255,.96), border rgba(0,0,0,.14), row ink
#263140, row hover rgba(15,23,42,.07), quiet ink #7A8491, chevron
#94A3B8, shadow 0 18px 34px rgba(15,23,42,.12),
0 2px 4px rgba(15,23,42,.05), inset 0 1px 0 rgba(255,255,255,.74).
- Dark, neutral grays with no blue cast: surface rgba(34,34,34,.96),
border rgba(255,255,255,.12), row ink #E4E4E4, row hover
rgba(255,255,255,.08), quiet ink #9A9A9A, chevron #8A8A8A, shadow
0 18px 34px rgba(0,0,0,.42), 0 2px 4px rgba(0,0,0,.2),
inset 0 1px 0 rgba(255,255,255,.06).
- Monochrome brand icons invert in dark. Switching themes cross-fades
colors, borders and shadows over about 500ms.
Keep every timing value as a named constant in one place, and keep the
safe-zone math in a pure, unit-tested helper (point-in-triangle by the
sign of the three edge cross products). Add an optional debug overlay that
draws the zone (blue fill at 16%, dashed blue outline) and the running
timer, off by default.




















