Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vbabel
Copy link
Contributor

@vbabel vbabel commented Nov 24, 2025

This is a small fix that allows buttons in the UI to be pressed via the keyboard when the spacebar is pressed.

I presume the keydown and keyup listeners were prevent default and stopping propagation in order to prevent the default scrolling behavior of the spacebar. This was also preventing the buttons in the UI from being pressed when they have focus.

This allows buttons to continue to be pressed by checking the active element (within the shadow root) and not preventing default or stopping propagation if it is a button tag.

@pocka pocka added this to the v2.1.0 milestone Nov 25, 2025
Copy link
Owner

@pocka pocka left a comment

Choose a reason for hiding this comment

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

Thanks, good catch!

The code still triggers drag operation, which is unnecessary. Appending condition in the above early returns would be suffice.

if (ev.key !== FrameCanvas.DRAG_MODE_KEY || /* here */) {
      return;
}

// or new `switch` statement here if there are more elements that accept space key.
switch (document.activeElement?.shadowRoot?.activeElement?.tagName) {
  case "BUTTON":
  case "SOME_ELEMENT_IDK":
    return;
  default:
    break;
}

@vbabel
Copy link
Contributor Author

vbabel commented Nov 25, 2025

The code still triggers drag operation, which is unnecessary. Appending condition in the above early returns would be suffice.

The reason I didn't just exit early is because if a user clicks a button with the mouse it receives focus, but not visibly. So for instance if a user clicks the copy button and doesn't interact with any other element, the copy button is still focused and hitting the spacebar will click it again rather than allowing drag mode to be entered, which might be confusing.

I figured just allowing the user to drag while focused on a button was better. I do think it's a bit strange, but I prefer it to the above scenario. Personally I'd avoid using the spacebar for this sort of action, but in this case I understand that this is replicating figma behavior.

@vbabel vbabel changed the title allow UI buttons to be pressed via spacebar Allow UI buttons to be pressed via spacebar Nov 25, 2025
@pocka
Copy link
Owner

pocka commented Nov 25, 2025

I checked the Figma for this situation and they don't activate drag / pan mode when the focus is on a sidebar element.

The correct place to improve keyboard usability is the canvas (non focusable, almost no keyboard controls) rather than the inspector panel.

@vbabel vbabel force-pushed the victor/fix-kb-button-presses branch from aae9925 to d75951f Compare November 27, 2025 00:16
@vbabel
Copy link
Contributor Author

vbabel commented Nov 27, 2025

The correct place to improve keyboard usability is the canvas (non focusable, almost no keyboard controls) rather than the inspector panel.

Yeah I have WIP on this that I plan on opening a draft PR for, I have the focusing/drill in/out behavior similar to figma, but am kinda stuck on what to do about the focus looping and allowing the user to navigate to the inspector panel.

@vbabel
Copy link
Contributor Author

vbabel commented Nov 27, 2025

@pocka I just pushed up a different solution, I think this one is a bit better, it only allows drag mode to be enabled when the viewport is hovered and focus is not on some other element, thus preventing the keydown handler from stopping normal spacebar actions such as scrolling or pressing buttons in those situations.

Copy link
Owner

@pocka pocka left a comment

Choose a reason for hiding this comment

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

This feels natural and I like that there is no hacky code here. Focus management code tends to be hacky tangled spaghetti, but this patch is simple and easy to understand!

I left some style-related comments.

@vbabel vbabel force-pushed the victor/fix-kb-button-presses branch from d75951f to 6de74a8 Compare November 27, 2025 18:17
@vbabel vbabel requested a review from pocka November 27, 2025 18:18
@pocka pocka merged commit ae812ca into pocka:master Nov 30, 2025
1 check passed
@vbabel vbabel deleted the victor/fix-kb-button-presses branch December 1, 2025 16:02
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