Skip to content

fix(focus-ring): prevent visible ring on label click #5807

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions focus/internal/focus-ring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export class FocusRing extends LitElement implements Attachable {
default:
return;
case 'focusin':
this.visible = this.control?.matches(':focus-visible') ?? false;
// Related target is null for elements that cannot be focused.
// This is will prevent HTMLLabelElements to set visible to true.
// developer.mozilla.org/en-US/docs/Web/API/FocusEvent/relatedTarget
this.visible = (event.relatedTarget !== null && this.control?.matches(':focus-visible')) ?? false;
break;
case 'focusout':
case 'pointerdown':
Expand Down Expand Up @@ -112,6 +115,6 @@ export class FocusRing extends LitElement implements Attachable {

const HANDLED_BY_FOCUS_RING = Symbol('handledByFocusRing');

interface FocusRingEvent extends Event {
interface FocusRingEvent extends FocusEvent {
[HANDLED_BY_FOCUS_RING]: true;
}