Skip to content

fix(edit): keep focus on the used move button when reordering options - #3937

Merged
AndyScherzinger merged 1 commit into
nextcloud:mainfrom
bhardwajhimanshu2515:fix/option-reorder-menu-focus
Nov 20, 2026
Merged

AndyScherzinger merged 1 commit into
nextcloud:mainfrom
bhardwajhimanshu2515:fix/option-reorder-menu-focus

Conversation

@bhardwajhimanshu2515

@bhardwajhimanshu2515 bhardwajhimanshu2515 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2595

Cause. After an option is moved, the move-up/move-down buttons change their disabled state, so NcActions re-renders and, in a $nextTick, moves focus to its first action unless one of its items carries the active class. focusButton() also called focus() on the action's <li> wrapper (NcActionButton's root), which is not focusable. Result: after "Move option down" focus jumped to "Move option up".

The open menu also briefly disappeared while moving: it is rendered inside its option's list item, and while the options animate into their new order each moving item gets its own stacking context, so the items below painted over the menu.

Fix.

  • focusButton() now focuses the <button> inside the action and marks its item active, the same thing NcActions does when it focuses an action itself. Focus stays on the button that was used, or moves to the other one when the option reaches the top or bottom. This now lives in src/utils/FocusActionItem.ts.
  • The list item whose menu is open is lifted above its siblings, so the menu stays on top during the reorder animation.
  • The ranked list in the respondent view of a ranking question had the same two problems and gets the same fixes. It also looked up the move buttons by position in refs that Vue keeps in mount order, so after a reorder it could focus another item's button; it now looks them up by option id. The ranking question's editor uses AnswerInput.vue and is covered by the first two fixes.

Testing. I couldn't run a Nextcloud instance here, so I reproduced it with a minimal page using the same @nextcloud/vue NcActions/NcActionButton setup (keyed list, menu container inside the row) and Playwright:

  • before: moving the first option down left focus on "Move option up"
  • after: focus stays on "Move option down"; moving an option to the top focuses "Move option down"

For the menu layering and the ranking fixes: open the move menu of an option (checkboxes, radio buttons, dropdown and ranking in the editor, and a ranked item when answering a ranking question) and move it up and down several times. The menu should stay visible during the animation and focus should stay on the used button. This was tested on a live Nextcloud 36 instance with a form containing all four question types.

eslint passes for the changed files, npm run build succeeds, and npm run typecheck shows the same pre-existing errors before and after.

  • Signed-off commit (DCO)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@AndyScherzinger AndyScherzinger added bug Something isn't working 3. to review Waiting for reviews labels Nov 19, 2026
@AndyScherzinger AndyScherzinger added this to the 5.5 milestone Nov 19, 2026
@AndyScherzinger
AndyScherzinger force-pushed the fix/option-reorder-menu-focus branch from 88f9836 to 090221b Compare November 20, 2026 10:48
@AndyScherzinger

Copy link
Copy Markdown
Member

Tested on a Nextcloud 36 dev instance with a keyboard-only Playwright run: a multiple choice question with options A, B, C, the move menu of A opened with Enter, then Enter on the move buttons to go down, down, up, up. After each step the test checks the option order and which button has focus.

Step This PR main without the fix
A down to the middle, focus stays on "Move option down" ✅ ✅
A down to the bottom, focus moves to "Move option up" ✅ ✅
A up to the middle, focus stays on "Move option up" ✅ ❌ focus lost to <body>
A up to the top, focus moves to "Move option down" ✅ ❌ focus lost

The PR passed all steps in four runs. ESLint and Prettier are clean on AnswerInput.vue. Not covered: screen readers, mouse use, and browsers other than Chromium.

I rebased the branch onto main and added a separate commit that limits the docblock of focusButton() to what the function does. The explanation of the NcActions behaviour is already in the commit message of the fix.

@Chartman123 could you please review?

Assisted by ClaudeCode:claude-opus-5-5

@Chartman123

Copy link
Copy Markdown
Collaborator

Looks good, the focus is kept correctly, but this still doesn't fix the visual glitch while moving:

Bildschirmaufnahme.2026-11-20.130426.mp4

AndyScherzinger added a commit to bhardwajhimanshu2515/forms that referenced this pull request Nov 20, 2026
The move menu of an option is rendered inside the option's list item.
While the options animate into their new order, every moving item gets
a transform and so its own stacking context, and the items after the
one with the open menu were painted over the menu.

Lift the list item above its siblings while its menu is open.

Ref: nextcloud#3937 (comment)

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
AndyScherzinger added a commit to bhardwajhimanshu2515/forms that referenced this pull request Nov 20, 2026
The ranked list that respondents reorder has its own move menu with
the same problems the option editor had: focus went to the item
wrapper instead of the button, and the open menu was painted over by
the following items while they animated into their new order.

It also looked the move buttons up by position in refs that Vue keeps
in mount order, so after a reorder it could focus another item's
button. Look them up by option id instead, share the focus handling
with the option editor, and lift the item with the open menu above
its siblings.

Ref: nextcloud#3937 (comment)

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@AndyScherzinger

Copy link
Copy Markdown
Member

@Chartman123 thanks for the video. The menu is rendered inside its option's list item, and while the options animate into their new order each moving item gets its own stacking context, so the items below painted over the open menu. 97a9cb6 lifts the item with the open menu above its siblings.

The ranked list in the respondent view had the same three issues, so 93411db covers it too: the same layering fix, the same focus fix (now shared in src/utils/FocusActionItem.ts), and the move buttons are looked up by option id because the positional refs stayed in mount order after a reorder and could focus another item's button.

@bhardwajhimanshu2515 I pushed both commits to your branch, so please pull before pushing again.

After an option is moved, the move-up/move-down buttons change their
disabled state, NcActions re-renders and then moves focus to its first
action unless one of its items is marked active. The previous code also
focused the action's <li> wrapper instead of its button. Focus the
button and mark its item active, so focus stays on the button that was
used (or the other one once the option reaches the top or bottom).

The move menu is rendered inside the option's list item. While the
options animate into their new order, every moving item gets a
transform and so its own stacking context, and the items after the one
with the open menu were painted over the menu. Lift the list item
above its siblings while its menu is open.

The ranked list that respondents reorder in a ranking question had the
same two problems and gets the same fixes. It also looked the move
buttons up by position in refs that Vue keeps in mount order, so after
a reorder it could focus another item's button; look them up by option
id instead. The focus handling is shared in FocusActionItem.ts.

Fixes nextcloud#2595

Co-authored-by: Himanshu Bhardwaj <bhardwajhimanshu2515@gmail.com>
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Himanshu Bhardwaj <bhardwajhimanshu2515@gmail.com>
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@AndyScherzinger
AndyScherzinger force-pushed the fix/option-reorder-menu-focus branch from 93411db to f670d5a Compare November 20, 2026 13:35
@AndyScherzinger

Copy link
Copy Markdown
Member

@bhardwajhimanshu2515 I squashed the PR into a single commit (f670d5a), with you as co-author and your sign-off kept. If you have a local copy of the branch, please reset it before pushing again:

git fetch origin
git reset --hard origin/fix/option-reorder-menu-focus

@AndyScherzinger
AndyScherzinger merged commit 204c521 into nextcloud:main Nov 20, 2026
43 checks passed
@AndyScherzinger

Copy link
Copy Markdown
Member

/backport to stable5.4

@backportbot backportbot Bot added the backport-request Pending backport by the backport-bot label Nov 20, 2026
@Chartman123

Copy link
Copy Markdown
Collaborator

/backport to stable5.4

@backportbot

backportbot Bot commented Nov 20, 2026

Copy link
Copy Markdown

The backport to stable5.4 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable5.4
git pull origin stable5.4

# Create the new backport branch
git checkout -b backport/3937/stable5.4

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts, resolve them
git cherry-pick f670d5a8

# Push the cherry pick commit to the remote repository and open a pull request
git push origin backport/3937/stable5.4

Error: Failed to create pull request: Validation Failed: {"resource":"PullRequest","code":"custom","message":"A pull request already exists for nextcloud:backport/3937/stable5.4."} - https://docs.github.com/rest/pulls/pulls#create-a-pull-request


Learn more about backports at https://docs.nextcloud.com/server/stable/go.php?to=developer-backports.

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

Labels

3. to review Waiting for reviews AI assisted bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menu for re-ordering options must be improved

3 participants