salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.63k stars 395 forks source link

[delegatesFocus] Shadow host should receive focus event when focus enters the shadow tree #1244

Open ekashida opened 5 years ago

ekashida commented 5 years ago

Description

The host element should always receive the focus event whenever focus enters the shadow tree, regardless of the delegatesFocus or tabindex value (needs spec verification).

The current workaround is for the component to dispatch a focus event when it detects focus inside the shadow tree.

Steps to Reproduce

1242

ekashida commented 5 years ago

Possible solution: Dispatch focus when needed, but need to investigate concerns around isTrusted and whether relatedTarget gets set correctly.

ekashida commented 4 years ago

Also, don't forget about blur.

gonzalocordero commented 2 years ago

@ekashida @gregwhitworth now that we are doing native shadow, this might be a good time to revisit this issue.

nolanlawson commented 1 year ago

Another difference in native shadow and synthetic shadow was discovered around this.

Standard focus and blur events work differently. Consider a focusable element like:

<template>
   <input type="text">
</template>

In synthetic shadow, focus and blur do not bubble up. E.g.:

<lightning-component 
  onfocus={iWillNotBeExecuted} 
  onblur={iWillNotBeExecuted}
></lightning-component>

In native shadow, blur and focus do bubble:

<lightning-component 
  onfocus={iWillBeExecutedIfInputisFocussed} 
  onblur={iWillBeExecutedIfInputIsBlurred}
></lightning-component>

(/ht to John Hefferman for this.)