Skip to content

feat: Auto-focus on click (browser-like behavior)#584

Merged
kommander merged 10 commits intoanomalyco:mainfrom
eitanalka:feature-auto-focus-on-click
Jan 30, 2026
Merged

feat: Auto-focus on click (browser-like behavior)#584
kommander merged 10 commits intoanomalyco:mainfrom
eitanalka:feature-auto-focus-on-click

Conversation

@eitanalka
Copy link
Contributor

@eitanalka eitanalka commented Jan 25, 2026

Fixes Issue #576

Problem

Currently, clicking on a focusable element (input, scrollbox, etc.) doesn't automatically focus it. Users must manually handle onMouseDown to set focus state, which is different from browser behavior.

Proposed Solution

Add browser-like auto-focus behavior to the renderer:

  • Left-click triggers focus() on the clicked element
  • If the element isn't focusable, bubble up to find the closest focusable ancestor
  • Uses the same parent traversal pattern as isWithinContainer

Benefits

  • Matches expected browser behavior
  • Simplifies component code (no manual onMouseDown handlers needed)
  • Works seamlessly with focusedBorderColor/focusedBackgroundColor style props

eitanalka and others added 2 commits January 23, 2026 11:08
Automatically focus the closest focusable ancestor when clicking with
the left mouse button. This matches browser behavior where clicking
inside a focusable container focuses it.

- Walks up parent chain to find first focusable element
- Works with scrollbox, input, textarea, select components
- Adds test coverage for focus-on-click behavior

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 25, 2026

@opentui/core

npm i https://pkg.pr.new/anomalyco/opentui/@opentui/core@584

@opentui/react

npm i https://pkg.pr.new/anomalyco/opentui/@opentui/react@584

@opentui/solid

npm i https://pkg.pr.new/anomalyco/opentui/@opentui/solid@584

@opentui/core-darwin-arm64

npm i https://pkg.pr.new/anomalyco/opentui/@opentui/core-darwin-arm64@584

@opentui/core-darwin-x64

npm i https://pkg.pr.new/anomalyco/opentui/@opentui/core-darwin-x64@584

@opentui/core-linux-arm64

npm i https://pkg.pr.new/anomalyco/opentui/@opentui/core-linux-arm64@584

@opentui/core-linux-x64

npm i https://pkg.pr.new/anomalyco/opentui/@opentui/core-linux-x64@584

@opentui/core-win32-arm64

npm i https://pkg.pr.new/anomalyco/opentui/@opentui/core-win32-arm64@584

@opentui/core-win32-x64

npm i https://pkg.pr.new/anomalyco/opentui/@opentui/core-win32-x64@584

commit: bd3b8dc

eitanalka and others added 4 commits January 25, 2026 12:54
Fire mousedown event before auto-focus so handlers can call
preventDefault() to cancel the default focus behavior (browser-like).

Adds tests for preventDefault and verifies mousedown fires only once.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kommander
Copy link
Collaborator

I added test coverage for the mouse data handler on main. Can you merge that in or let me push to your branch?

@eitanalka
Copy link
Contributor Author

I added test coverage for the mouse data handler on main. Can you merge that in or let me push to your branch?

I updated the branch and gave permission to push to the branch just in case you need to modify it still.

@kommander kommander merged commit fd059c0 into anomalyco:main Jan 30, 2026
4 of 5 checks passed
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.

feat: Auto-focus on click (browser-like behavior)

2 participants