Skip to content

[menu] moving keyboard focus into submenus #1439

Open

Description

@davidsgrogan
<button commandfor=menulist command=toggle-menu>command=toggle-menu</button>
<menubar>
  <menuitem commandfor=menulist command=toggle-menu>command=toggle-menu</menuitem>
</menubar>

<menulist id="menulist">
  <menuitem>menuitem 1</menuitem>
  <menuitem>menuitem 2</menuitem>
  <menuitem>menuitem 3</menuitem>
  <menuitem>menuitem 4</menuitem>
  <menuitem>menuitem 5</menuitem>
</menulist>

https://davidsgrogan.github.io/menu-keyboard.html (Try on Chrome Dev/Canary with experimental-web-platform-features enabled)

When activating the menulist via the keyboard (focus then <ENTER> or <SPACE>), should focus move into the submenu so that you can use the up/down arrow keys to focus the menuitems? Or should moving focus into the submenu require an extra <TAB> keypress?

Should the answers be the same no matter if the source of the activation is the button vs the menuitem?

/cc @josepharhar

Activity

  1. added
    agenda+
    menu
    on Apr 28, 2026
  2. scottaohara commented on Apr 29, 2026

    @scottaohara
    Collaborator

    Focus should move to the invoked menu’s first focusable menu item element.

  3. pinned this issue on Apr 29, 2026
  4. css-meeting-bot commented on Apr 30, 2026

    @css-meeting-bot

    The Open UI Community Group just discussed [menu] moving keyboard focus into submenus, and agreed to the following:

    • RESOLVED: when activating a menuitem or button which opens a submenu with with space or enter or arrow down or arrow right, focus should move to the first focusable menuitem in the submenu. with arrow up, focus moves to the last menuitem in the submenu
    The full IRC log of that discussion <masonf> jarhar: another menu thing.
    <masonf> ...if you have a button that invokes a menulist or a menuitem that invokes a submenu, and you invoke with keyboard space/enter, focus doesn't move.
    <masonf> ...in the case of the button, you have to hit tab. For menuitem, it's arrow keys.
    <masonf> ...with the button that feels weird. Seems right to just automatically move focus in this case.
    <masonf> ...for the menuitem with submenu, easier to figure out, but still nice to move focus.
    <lwarlow> q+
    <sorvell> q+
    <masonf> ...for popovers, it only moves focus if there's an `autofocus` element contained.
    <scott> q+
    <masonf> ...let's move focus automatically for menus.
    <masonf> lwarlow: I think moving it automatically makes sense.
    <masonf> ...different from popover. Popovers have a lot of patterns, some don't want autofocus.
    <masonf> +1 from the scribe
    <keithamus> ack lwarlow
    <masonf> ...the demo linked for the menu (menubar with menuitem that opens) is weird, because you arrow down to get into it, but arrow back up loops back to the bottom of the menu.
    <masonf> ...in both cases, autofocus is better.
    <vmpstr> q+
    <masonf> ...likewise for button with menulist.
    <masonf> sorvell: if I understand - current behavior is broken. All menus normally do this. Move the focus.
    <keithamus> ack sorvell
    <Jacques> +1, after activating a menu arrow keys should immediately be available to move focus around
    <masonf> scott: there are bad patterns out there. But yes this is the expected behavior - move the focus.
    <keithamus> ack scott
    <masonf> ...users expect focus to automatically move.
    <masonf> ...only reason you might not do that is a weird edge case (designer with the wrong opinion)
    <lwarlow> q+
    <sorvell> q+
    <masonf> ...Joey you asked about menulist rule should be for other content, maybe we can talk at the end.
    <masonf> vmpstr: question about this. If you have autofocus, this will be the behavior. If we make this the default, is there a way to opt out?
    <keithamus> ack vmpstr
    <masonf> qq+
    <Jacques> q+
    <masonf> ...trying to find examples - Mac bar menu doesn't autofocus first item.
    <scott> q+
    <jarhar> q+
    <masonf> ack masonf
    <Zakim> masonf, you wanted to react to vmpstr
    <keithamus> masonf: Everything I've heard from this discussion is that focus is correct, so I don't want an easy opt out. We've decided things are possible with JS, so that seems like the way to opt out. Posssible not easy
    <keithamus> ack lwarlow
    <masonf> lwarlow: MacOS difference is that focusing the menuitem within menubar at the top opens the menu automatically. But proposal is that menuitem needs to be activated to open it.
    <masonf> ...if we make this autofocus automatically, fine. If I wanted to create MacOS behavior, I'd have to use JS right? If so, if I want manual buttons, like a custom element. Do I have to do this behavior myself? Having the JS differ might be odd.
    <masonf> jarhar: I think what we're doing is an improvement on MacOS. When I focus on menu items, it is interest invoking them (don't have to click). We want to do that also. But when you press space or enter to explicitly activate it, then we will move focus. But MacOS is weird because if you press space or enter, it *closes* the menu. Which is weird.
    <masonf> ...we're aligned with MacOS but also improving it.
    <masonf> lwarlow: intended behavior is that if you focus on menuitem in a menubar, it will open the menu but won't activate the menu. Right?
    <masonf> jarhar: yes, after a delay, it'll open the menu but won't move the focus.
    <dbaron> (yeah, it seems like the MacOS behavior is inconsistent between items in a menubar versus items in a menulist)
    <masonf> sorvell: pretty nuanced. I want to highlight an example from the Mac menubar. Click View, a menu pops up below. Different than if you have a menu that goes off to the side.Behavior should be different for menubar vs. menulist.
    <jarhar> q+
    <masonf> ...also problem with focus the first item. Horizontal menubar, submenu has 500 items. Press up arrow and that goes to the bottom. Doesn't wrap.
    <masonf> (But it does wrap!)
    <dbaron> qq+ about wrapping
    <jarhar> we can implement that too, if you use arrow keys to move focus into the submenu instead of using space or enter to move focus into the submenu
    <masonf> ...bookmarks are another example. Like to use up arrow. Want to preserve that.
    <masonf> ...example linked is kind of broken. Menu should always be focused. First key is important.
    <keithamus> ack sorvell
    <masonf> dbaron: most menus actually wrap. MacOS is the weird one in not wrapping. Plan was to make menus wrap.
    <masonf> Gnome menus, google docs menus, and {} menus all wrap.
    <dbaron> (I think)
    <masonf> sorvell: Chrome on Mac doesn't agree with Apple OS way. As a user it's tough.
    <lwarlow> ack jackques
    <lwarlow> ack jackques
    <lwarlow> ack jacques
    <masonf> Jacques: I agree with Steve on the behavior of the MacOS, except wrapping. In both up/down/left/right directions.
    <keithamus> ack about
    <Zakim> about, you wanted to react to lwarlow
    <masonf> sorvell: View menu then up arrow, I get to the bottom. Then down arrow doesn't wrap to the top.
    <masonf> dbaron: I see that it doesn't wrap.
    <masonf> sorvell: there should be a way to get to the bottom of a menu. Somehow. Wrapping is fine. Just make this work.
    <lwarlow> It doesn't wrap for me fwiw, but does on the menubar. I suspect much of this will be UA dependent, so ultimately it's up to the browsers.
    <keithamus> ack scott
    <masonf> scott: autofocus and popovers. Reminder: popover can be one of many things, so nothing autofocuses there. But that's different for menus - the whole point there is to use menu items inside a menu. Don't make users do more work in this case.
    <masonf> ...menubar with auto-opening submenus. How would you do that? I would have expected to do that with CSS - if you want to have open-on-hover/focus, use CSS. I wouldn't want that behavior. There are menus where you don't want that - you have to hit a key.
    <keithamus> ack jarhar
    <masonf> jarhar: controllable via CSS.
    <lwarlow> q+
    <keithamus> Zakim, close the queue
    <Zakim> ok, keithamus, the speaker queue is closed
    <masonf> ...going back to Steve's use case, this is already handled via the proposed wrapping behavior.
    <jarhar> proposed resolution: when activating a menu item with the keyboard with space or enter, focus should move to the first focusable menuitem in the submenu
    <masonf> ...prototype does what you want - up arrow takes you to the last item.
    <keithamus> ack lwarlow
    <masonf> dbaron: hover-trigger on menubar if there's already an open menu. But not generally.
    <masonf> masonf: via interest invokers `interest-delay`.
    <masonf> +1 to resolution
    <dbaron> +1
    <lwarlow> neutral, I think I want to play with a demo before +1ing
    <masonf> sorvell: I'm only onboard if we wrap
    <masonf> sorvell: include that in the resolution please
    <sorvell> +1
    <jarhar> proposed resolution: when activating a menuitem or button which opens a submenu with with space or enter, focus should move to the first focusable menuitem in the submenu
    <lwarlow> s/with with/with
    <jarhar> proposed resolution: when activating a menuitem or button which opens a submenu with with space or enter or arrow down or arrow right, focus should move to the first focusable menuitem in the submenu. with arrow up, focus moves to the last menuitem in the submenu
    <masonf> +1
    <dgrogan> +1
    <scott> +1
    <sorvell> +1
    <keithamus> +1
    <Jacques> +1
    <dbaron> +1
    <sbender> +1
    <jarhar> RESOLVED: when activating a menuitem or button which opens a submenu with with space or enter or arrow down or arrow right, focus should move to the first focusable menuitem in the submenu. with arrow up, focus moves to the last menuitem in the submenu
  5. removed
    agenda+
    on May 1, 2026
  6. tom-sherman commented on May 13, 2026

    @tom-sherman

    I'd recommend reading w3c/aria-practices#2206 which is a very similar discussion to this one, relating specifically to the UX for mouse/pointer users.

    From a subjective UX POV and also my interpretation of the ARIA consensus in that discussion it seems perfectly valid to not focus the first menu item when the menu is opened with a mouse/pointer.

  7. josepharhar commented on May 26, 2026

    @josepharhar
    Collaborator

    Thanks, I'll avoid moving focus when menuitems are activated with pointer inputs for now.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    menuneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions