Skip to content

Add programmatic element focus and blur - #76

Draft
cowboyd wants to merge 1 commit into
dom-is-connectedfrom
dom-focus
Draft

cowboyd wants to merge 1 commit into
dom-is-connectedfrom
dom-focus

Conversation

@cowboyd

@cowboyd cowboyd commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Implement explicitly focusing and blurring and the according event dispatch. This is a prerequisite for events moving focus around.

The existing focus cases now run directly from upstream WPT on the native WPT base (#87). Relevant specs: HTML’s focusing steps and DOM’s event dispatch.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

@pkg-pr-new

pkg-pr-new Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/bombshell-dev/ui/@clack/ui@76

commit: fb755a1

@cowboyd
cowboyd added this pull request to stack #77 November 14, 2026 06:33
@cowboyd
cowboyd marked this pull request as ready for review November 14, 2026 06:35
@cowboyd cowboyd mentioned this pull request Nov 14, 2026
3 of 9 tasks

@natemoo-re natemoo-re left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just some suggestions! shaping up nicely

Comment thread packages/ui/src/dom.ts Outdated
this.notify = notify;
this.documentElement = this.createElement('html');
this.body = this.createElement('body');
this.body = this.createElement('body') as HTMLBodyElement;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we could type createElement to return the correct type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, we definitely could. It's going to be really handy when we start making JSX integrations, especially with custom elements.

I'm a bit at a loss as to the best way to do it now however. I mean, there are a couple ways we could go about it, but I do worry that a solution invested in now, might just get in the way of our ultimate solution.

I agree that it's something we should do though. If we can record it somewhere, is a follow-on ok?

Comment thread packages/ui/src/dom.ts Outdated
if (!this.isConnected) {
return;
}
this.ownerDocument._setActiveElement(this);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

interesting! do you know how the browser handles privileged methods like this?maybe this could be a local function that stores state per document in a WeakMap or something? there's probably a nicer way than that, just the first thing that came to mind.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we could do it that way. It would certainly make it so that don't have a "rogue" public method that someone could invoke on their own.

Comment thread packages/ui/src/dom.ts Outdated
}

get activeElement(): Element {
return this.#activeElement ?? this.body;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

body is the default activeElement? TIL!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

who knew?!?

@cowboyd
cowboyd marked this pull request as draft November 17, 2026 17:46
@cowboyd
cowboyd force-pushed the dom-focus branch 2 times, most recently from 2741801 to 97a7748 Compare November 17, 2026 21:43
@cowboyd
cowboyd removed this pull request from stack #77 November 17, 2026 22:40
@cowboyd
cowboyd added this pull request to stack #92 November 17, 2026 22:40
@cowboyd
cowboyd removed this pull request from stack #92 November 17, 2026 22:49
@cowboyd
cowboyd added this pull request to stack #94 November 17, 2026 22:49
@cowboyd
cowboyd removed this pull request from stack #94 November 18, 2026 02:24
@cowboyd
cowboyd added this pull request to stack #96 November 18, 2026 02:24
@cowboyd
cowboyd removed this pull request from stack #96 November 18, 2026 02:27
@cowboyd
cowboyd added this pull request to stack #98 November 18, 2026 02:27
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