Skip to content

Commit

Permalink
[cleanup] Remove incorrectly overridden focus() method.
Browse files Browse the repository at this point in the history
The `Button` component didn't override `focus()` correctly, as it wasn't
accepting (and passing through) the `FocusOptions`. It's also
unnecessary to even override the `focus()` method, since we pass
`delegatesFocus: true` when creating the shadow root.

Bug: 301364727
Change-Id: I946204ae086ee6344b099f332da065eb401abafe
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6179965
Reviewed-by: Alex Rudenko <[email protected]>
Commit-Queue: Benedikt Meurer <[email protected]>
Auto-Submit: Benedikt Meurer <[email protected]>
  • Loading branch information
bmeurer authored and Devtools-frontend LUCI CQ committed Jan 17, 2025
1 parent f40d63c commit 63c5ce0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 20 additions & 0 deletions front_end/ui/components/buttons/Button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ describe('Button', () => {
assert.isTrue(button.disabled);
});

describe('focus', () => {
it('correctly focuses the <button> element in the shadow DOM', () => {
const button = renderButton();

button.focus();

assert.isTrue(button.shadowRoot!.querySelector('button')!.hasFocus());
});
});

describe('hasFocus', () => {
it('correctly reflects the focus state of the button', () => {
const button = renderButton();

button.focus();

assert.isTrue(button.hasFocus());
});
});

it('primary button can be clicked', () => {
testClick({
variant: Buttons.Button.Variant.PRIMARY,
Expand Down
4 changes: 0 additions & 4 deletions front_end/ui/components/buttons/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ export class Button extends HTMLElement {
this.#render();
}

override focus(): void {
this.#shadow.querySelector('button')?.focus();
}

connectedCallback(): void {
this.#render();
}
Expand Down

0 comments on commit 63c5ce0

Please sign in to comment.