Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent focus loss when chat code block toolbar dropdown More... closes #244990

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

meganrogge
Copy link
Contributor

@meganrogge meganrogge commented Mar 28, 2025

fixes https://github.com/microsoft/vscode-copilot/issues/9362

Fixing this as a priority today because will be out most of next week and this should've been fixed awhile ago. I thought it was invalid because had only tried on mac, where we use the native menu. It's an issue on windows and linux, where we use the custom context menu.

To test the fix on mac, I modified these lines so the custom context menu was used:

if (!isMacintosh && !hasNativeTitlebar(configurationService)) {

Before:

demo2.mov

After:

demo.mov

@meganrogge meganrogge requested a review from Tyriar March 28, 2025 17:06
@meganrogge meganrogge self-assigned this Mar 28, 2025
@meganrogge meganrogge added this to the April 2025 milestone Mar 28, 2025
@meganrogge meganrogge enabled auto-merge (squash) March 28, 2025 17:10
@meganrogge meganrogge requested a review from bpasero March 28, 2025 21:28
@meganrogge meganrogge marked this pull request as draft March 28, 2025 21:28
auto-merge was automatically disabled March 28, 2025 21:28

Pull request was converted to draft

@meganrogge
Copy link
Contributor Author

@bpasero, do you have any insights here?

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem like the right approach. We have other instances of dropdowns that only show on hover and the issue does not apply there, notice how the "..." remains visible even when the menu shows:

image

I would suggest to review how other "..." entries are doing it, here for example the "..." in the "Repositories" view.

image

@meganrogge
Copy link
Contributor Author

meganrogge commented Mar 31, 2025

@bpasero , you are right. This works for all of the other consumers - just not the chat code block toolbar's dropdown.

I found that commenting out this line (with no other changes) fixes it cc @roblourens

.interactive-result-code-block .interactive-result-code-block-toolbar {
display: none;

@meganrogge meganrogge force-pushed the merogge/fix-dropdown-focus branch from dec1734 to ff02fe4 Compare March 31, 2025 15:58
@meganrogge
Copy link
Contributor Author

demo.mov

@meganrogge meganrogge dismissed bpasero’s stale review March 31, 2025 16:21

addressed in just the chat toolbar

@meganrogge meganrogge requested a review from roblourens March 31, 2025 16:21
@meganrogge meganrogge force-pushed the merogge/fix-dropdown-focus branch from 0670a21 to 9e2787f Compare March 31, 2025 16:25
@meganrogge meganrogge marked this pull request as ready for review March 31, 2025 16:30
@meganrogge meganrogge changed the title prevent focus loss when More... menu closes for custom context menus prevent focus loss when More... menu closes chat code block toolbar dropdown Mar 31, 2025
@meganrogge meganrogge changed the title prevent focus loss when More... menu closes chat code block toolbar dropdown prevent focus loss when chat code block toolbar dropdown More... closes Mar 31, 2025
@bpasero
Copy link
Member

bpasero commented Mar 31, 2025

This looks nice, but can it be done without need for setTimeout still?

@meganrogge
Copy link
Contributor Author

@bpasero that is necessary to fix this as I describe in the comment.

@bpasero
Copy link
Member

bpasero commented Mar 31, 2025

But why do the other cases where we have this working not need to use setTimeout and can we try to mimic how it works there? 🤔

@meganrogge
Copy link
Contributor Author

The other cases do not hide the toolbar by default with display none, that removes it from the dom #244990 (comment)

@roblourens
Copy link
Member

I would expect notebook cell toolbars to have the same problem (if you set "notebook.cellToolbarVisibility": "hover"). Also, would using visibility or another method work instead of using display: none to hide the toolbar?

@meganrogge
Copy link
Contributor Author

meganrogge commented Mar 31, 2025

@roblourens I tried using visibility and opacity and got the same result

@meganrogge meganrogge force-pushed the merogge/fix-dropdown-focus branch from 9532e10 to 53e995c Compare March 31, 2025 21:06
@meganrogge meganrogge force-pushed the merogge/fix-dropdown-focus branch from 273eed0 to 9d6a2ae Compare March 31, 2025 21:11
@meganrogge
Copy link
Contributor Author

edit: opacity works - I was not applying it to all of the necessary places when I tested that before.

@meganrogge meganrogge enabled auto-merge (squash) March 31, 2025 21:16
@roblourens
Copy link
Member

Megan and I talked about this today, the new change with opacity is simpler but I'll look at this tomorrow, I'd like to understand more about why it needs that and doesn't work with fixing the rule but just using display.

@meganrogge
Copy link
Contributor Author

meganrogge commented Mar 31, 2025

AFAICT using display: none fully removes an element from the layout and accessibility tree, so when it’s made visible again, the browser needs a full frame to reflow and repaint before the element can receive focus—otherwise, .focus() may fail because the element isn’t yet interactable. In contrast, opacity: 0 keeps the element in the layout and accessibility tree, just visually hidden, so it can be focused immediately without waiting for a frame.

roblourens added a commit that referenced this pull request Apr 1, 2025
@roblourens
Copy link
Member

roblourens commented Apr 1, 2025

We have this flag, renderDropdownAsChildElement, AKA menuAsChild which renders the context menu as a child of the button. That makes focus easier to manage because you can use :focus-within but I think it breaks in certain places, that's why it's off by default. It seems like it works fine to set it here but I asked Steven for the history to confirm it's ok here. Here's a PR that does this: #245271

For the current state, here's my interpretation

I think my PR is much simpler, but, there is a separate issue here which the opacity fix could also help with. I swear there's an old issue but I can't find it and I'm sure I never will. The issue is that the codeblock toolbar comes after the editor in the tab order, so that you tab from the editor to the toolbar. If we'd like it to be before the codeblock, we can probably move it in the DOM (I don't know why it's like that, maybe to make it show above), then the opacity trick lets me tab directly onto the toolbar before it's visible. Also the renderDropdownAsChildElement trick and the opacity trick could be combined for the benefits of both.

Anyway that was interesting, I'll let you decide how to go forward @meganrogge

@meganrogge
Copy link
Contributor Author

meganrogge commented Apr 1, 2025

@roblourens thanks for investigating and explaining. Given using opacity fixes the focus problem and another issue, seems like we should go with this fix?

@roblourens
Copy link
Member

Sure, to be clear, it doesn't fix the other issue on its own, there would be another change to make there

@roblourens
Copy link
Member

Since you're about to be out, and I have all of this stuff paged into memory now, how about I take over and look at that other tabbing issue? I assume that from an accessibility standpoint it would make sense, if I'm tabbing through the response, to first tab to the codeblock toolbar, then second tab into the codeblock itself right?

@meganrogge
Copy link
Contributor Author

meganrogge commented Apr 1, 2025

I would think users would be annoyed with tabbing into a toolbar before tabbing into the code block bc they need to review the code block (ie tab into it) before deciding to take an action, if any.

@meganrogge
Copy link
Contributor Author

But yes, if you could pls take this over, that would be great. If you don't have time, maybe we should just fix the linked issue for now?

@roblourens
Copy link
Member

bc they need to review the code block (ie tab into it) before deciding to take an action

Oh ok then maybe we did it this way because we actually prefer it this way. In that case, it also seems like it could be confusing to shift+tab backwards into a codeblock, and focus the toolbar before the codeblock (which we get by using opacity). But also skipping the toolbar entirely when tabbing backwards seems confusing too (current state). But I can just take it over. I'll probably merge both my PR and your opacity change.

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.

4 participants