Skip to content

[6.x] Find current chips' action menus when moving focus in element select inputs - #20659

Open
brandonkelly wants to merge 2 commits into
6.xfrom
bugfix/element-select-last-action-btn
Open

brandonkelly wants to merge 2 commits into
6.xfrom
bugfix/element-select-last-action-btn

Conversation

@brandonkelly

Copy link
Copy Markdown
Member

Description

Current chips render their actions as a <craft-action-menu> with a slot="invoker" button. Only the deprecated disclosure-menu fallback still renders .btn.action-btn. getLastActionBtn() looked for .action-btn only, so on current chips it found nothing, and once an element select input was full, getNextLogicalFocusElement() had no focus target.

 getLastActionBtn()
-  container.querySelectorAll('.action-btn')
+  container.querySelectorAll('craft-action-menu > [slot="invoker"], .action-btn')

The same selector goes into both copies: core BaseElementSelectInput and the Yii adapter's Craft.BaseElementSelectInput, which still returns a jQuery collection (.find(…).last()).

element added, field now full
  focusNextLogicalElement()
    getNextLogicalFocusElement()
      getLastActionBtn()   → the last chip's action menu invoker (was null / empty)

This also gives the selector modal its triggerElement on a full field. #20652's container fallback for triggerElement in getModalSettings() stays as a last resort for full fields with no chip action menu, such as when showActionMenu is off. Its test "gives a full field’s modal its container to return to" boots a full field whose chips get action menus, so with this change it gets the last chip's invoker instead of the container; that test's fixture needs chips without action menus (e.g. showActionMenu: false) once both land.

Evidence

Unit tests: a full field's next focus target is the last chip's action menu invoker, in both copies.

  • Before: expected null to be <craft-button …> (core), expected +0 to be 1 (adapter)
  • After: both pass.

Browser: a server-rendered single-relation element select (limit 1, the UI kitchen sink's HTML renderer), choosing an entry with the keyboard:

  • Before: document.activeElement is <body>.
  • After: document.activeElement is the chip's <craft-button slot="invoker" aria-label="Actions">, with a visible focus ring.

The workbench doesn't load the Yii adapter, so the adapter copy was checked through its jQuery unit test only.

Related issues

brandonkelly and others added 2 commits November 13, 2026 06:19
Chips render their actions as a craft-action-menu with a slot="invoker"
button, so the .action-btn-only lookup found nothing, and focus was lost
once an element select input became full.

Amp-Thread-ID: https://ampcode.com/threads/T-0f39b248-dfd9-4abd-af51-991420229bc4
Co-authored-by: Amp <amp@ampcode.com>
@github-actions

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/ui — open Storybook

No changed components detected in this Storybook.

resources/js — open Storybook

No changed components detected in this Storybook.

This branch has not been deployed

No deployments
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.

1 participant