Skip to content

Add programmatic element focus and blur - #76

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

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.

Type of change

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

Checklist

  • All tests pass (pnpm test)
  • Files are formatted (pnpm format)
  • I have added/updated tests for my changes (if applicable)
  • 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: 70aa6a2

@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

@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
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
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
}

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?!?

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