Skip to content

Make the menu usable on touch devices in landscape - #446

Merged
pfalstad merged 2 commits into
pfalstad:dev-tsfrom
St0pfen:fix/touch-menus
Nov 22, 2026
Merged

pfalstad merged 2 commits into
pfalstad:dev-tsfrom
St0pfen:fix/touch-menus

Conversation

@St0pfen

@St0pfen St0pfen commented Nov 20, 2026

Copy link
Copy Markdown

The menu bar fell back to the desktop layout whenever the window was wider than 600px,
so on a phone held sideways the dropdowns had nowhere to go: long menus ran off the
bottom of the screen without scrolling (#430) and nested submenus opened to the right,
past the edge of the viewport, where they could not be reached (#431). Portrait worked,
because that is where the collapsed (hamburger) layout was used.

Two commits:

Make the menu usable on touch devices in landscape

  • The collapsed layout now applies to (pointer: coarse) as well, so touch devices get
    the same menu in both orientations. (pointer: coarse) is the primary input, so a
    laptop with a touchscreen and a mouse still gets the desktop bar.
  • The bare burger glyph becomes a labelled "Menu" button at the top left (it shows a
    close mark while the menu is open). The component search field, which sits at the
    right end of the bar with a higher z-index, had covered the icon completely.
  • Touch devices start without the 40px icon toolbar; the menu reaches the same commands
    and the canvas gains the height (Options > Toolbar brings it back).
  • Nested submenus expand inline (accordion), indented per level, instead of sideways,
    and opening one never scrolls the panel — the entry used to move out from under the
    finger and the next tap ran the first child command, silently adding an element.
  • Submenus open on tap rather than on touchstart (a swipe opened whatever was under
    the finger), and only on hover for a real mouse: a touch tap fires a synthesized
    mouseover, which shifted the entries so the following click missed. In the collapsed
    layout hover opens nothing at all.
  • Dismissal is decided in one place (dismissesMenus): an interaction inside a panel
    never closes the menus, and a tap within 16px of an open panel counts as aiming at it.
    This replaces the per-element stopPropagation calls, which never covered panels
    built elsewhere, separators or gaps.
  • The sidebar is sized from the width its contents are laid out for (128..166px) instead
    of a hardcoded 128px, which clipped the sliders and labels in landscape.
  • Sidebar sliders get touch-action: pan-y and only take horizontal drags, so a finger
    that lands on one to scroll the panel scrolls it instead of moving the slider.
  • Context menus stay inside the viewport and scroll when they are taller than the room
    below the touch point.

Close the menus and the sidebar once an element is picked

Picking an element left the hamburger menu list — and the sidebar, if it was open —
covering the canvas, so there was no visible spot to drop it: the first tap on the canvas
both dismissed the overlay and placed the element there, which is not where the user
aimed. Every way of picking a tool (menu item, submenu item, keyboard shortcut, toolbar
variant popup) ends in UIManager.setMouseMode(MODE_ADD_ELM), which now calls a new
closeMenusAndOverlays() in ts/Menus.ts: it closes the dropdowns as before and also
unchecks the two overlay triggers, #toptrigger (menu list) and #trigger (sidebar).
The desktop layout is untouched — those checkbox rules only exist inside the
(max-width: 600px), (pointer: coarse) media query, and there the sidebar keeps its
inline width.

A build with both commits running: https://circuit-demo.behrends.xyz/ — on a touch
screen, open the menu (or the sidebar), pick a component from Draw, and the canvas is
free to place it.

Tests: two new UI tests in ts/ui-tests/menus.spec.ts (touch layout: sidebar and menu
closed after picking, and the element still drags out normally; desktop: the sidebar
keeps its width — both fail without the change). tsc --noEmit and npm test (vitest,
185 tests) pass. In npm run test:ui, menus, polarcap and editing pass;
build-fullrect and build-td4 fail on this machine with and without the change.

Fixes #430
Fixes #431

On a phone held sideways the layout fell back to the desktop menu bar, where
the dropdowns have nowhere to go: long menus ran off the bottom of the screen
without scrolling (pfalstad#430) and nested submenus opened to the right, past the edge
of the viewport, where they could not be reached (pfalstad#431). The same code works in
portrait, where the collapsed (hamburger) layout is used.

* Apply the collapsed layout to (pointer: coarse) as well, so touch devices get
  the same menu in both orientations. (pointer: coarse) is the primary input, so
  a laptop with a touchscreen and a mouse still gets the desktop bar.
* Replace the bare burger glyph with a labelled, coloured "Menu" button at the
  top left (it shows a close mark while the menu is open). The component search
  field sits at the right end of the menu bar with a higher z-index and had
  covered the icon completely, leaving the menu unreachable; the field shifts
  right where the button needs the room.
* Start touch devices without the 40px icon toolbar: the menu reaches the same
  commands and the canvas gains the height (Options > Toolbar brings it back).
* Expand nested submenus inline (accordion), indented per level, instead of
  sideways; never scroll the panel while opening one: the entry moved out from
  under the finger and the next tap ran the first child command, silently
  adding an element.
* Open submenus on tap, not on touchstart (a swipe opened whatever was under the
  finger), and only on hover for a real mouse -- a touch tap fires a synthesized
  mouseover, which shifted the entries and made the following click miss. In the
  collapsed layout hover opens nothing at all: that layout is a list for tapping,
  and it is used by narrow windows as well, where hovering popped menus open.
* Decide dismissal in one place (dismissesMenus): an interaction inside a panel
  never closes the menus, and a tap within 16px of an open panel counts as
  aiming at it. That replaces the per-element stopPropagation calls, which never
  covered panels built elsewhere, separators or gaps, and it fixes taps beside
  the panel, at the submenu arrow or on the bar just above it, which used to
  close everything ("the menu closes by itself").
* Size the sidebar in the touch layout from the width its contents are laid out
  for (128..166px) instead of a hardcoded 128px, which clipped the sliders and
  labels on a wider screen in landscape.
* Give the sidebar sliders touch-action: pan-y and only take horizontal drags,
  so a finger that lands on a slider to scroll the panel scrolls it instead of
  moving the slider.
* Keep context menus inside the viewport and let them scroll when they are
  taller than the room below the touch point.

Fixes pfalstad#430
Fixes pfalstad#431
Picking a tool in the collapsed (touch) layout left the hamburger menu list
and the sidebar covering the canvas, so there was no visible place to drop
the element. setMouseMode(MODE_ADD_ELM) -- the one path every menu, submenu,
shortcut and toolbar selection goes through -- now closes the dropdowns and
unchecks both overlay triggers.

UI tests: touch layout (menus closed, element still placeable) and desktop
(sidebar untouched).
@pfalstad
pfalstad merged commit e998bf7 into pfalstad:dev-ts Nov 22, 2026
@pfalstad

Copy link
Copy Markdown
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants