Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Web-Facing Change PSA: Fix text selection on Shadow DOM with delegatesFocus

113 views
Skip to first unread message

Di Zhang

unread,
Nov 25, 2024, 2:01:06 PM11/25/24
to blink-dev

Contact emails

dizh...@chromium.org

Specification

https://dom.spec.whatwg.org/#shadowroot-delegates-focus

Summary

A shadow host with delegatesFocus set to true will delegate its focus to its first focusable child. On a mouse click event, the child will receive focus and the event will be marked as handled. This is a problem because the steps to handle text selection afterward are not run and the selection does not recognize the focused element as part of the selection. We fix this by continuing event handling even after an element was delegate focused and update how selection recognizes having focus in a shadow tree.



Blink component

Blink>DOM>ShadowDOM

TAG review

None

TAG review status

Not applicable

Risks



Interoperability and Compatibility

None



Gecko: Shipped/Shipping Can select text in shadow host with delegatesFocus = true.

WebKit: Shipped/Shipping Can select text in shadow host with delegatesFocus = true.

Web developers: Positive [1] https://stackoverflow.com/q/60260078/864715 [2] https://stackoverflow.com/q/62766250/864715

Other signals:

WebView application risks

Does this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications?

None



Debuggability

None



Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, ChromeOS, Android, and Android WebView)?

No

Is this feature fully tested by web-platform-tests?

Yes

https://wpt.fyi/results/shadow-dom/focus/text-selection-with-delegatesFocus.html?label=experimental&label=master&aligned



Flag name on about://flags

SelectionOnShadowDOMWithDelegatesFocus

Finch feature name

None

Non-finch justification

None

Requires code in //chrome?

False

Tracking bug

https://issues.chromium.org/issues/40622041

Sample links


http://lopsided-motion.glitch.me/text-select-bug.html
https://codepen.io/JRJurman/pen/gOqvxXz

Estimated milestones

Shipping on desktop133
Shipping on Android133
Shipping on WebView133


Anticipated spec changes

Open questions about a feature may be a source of future web compat or interop issues. Please list open issues (e.g. links to known github issues in the project for the feature specification) whose resolution may introduce web compat/interop risk (e.g., changing to naming or structure of the API in a non-backward-compatible way).

None

Link to entry on the Chrome Platform Status

https://chromestatus.com/feature/5134341540413440?gate=5134678561128448

This intent message was generated by Chrome Platform Status.

Stephen Chenney

unread,
Dec 3, 2024, 10:09:39 AM12/3/24
to Di Zhang, blink-dev
I agree this should be fixed. Thanks.

I';m wondering if there is any situation in which developers might be relying on the existing behavior? That is, using this "bug" to render content not-selectable.

Stephen.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CA%2BSS7eAVZOnENNhVUMEUU%2Bh2qEp8ZE13cTjnKR8wRLPstgxHaQ%40mail.gmail.com.

Di Zhang

unread,
Dec 3, 2024, 10:47:27 AM12/3/24
to blink-dev, Stephen Chenney, blink-dev, Di Zhang
It is possible, although unlikely. The bug has a 23 stars (meaning people are running into it) and this fix makes us behave the same way as Webkit and Gecko.
If someone wants to make text inside a shadow DOM not selectable, they can still set the CSS user-select property to none. It would be bad practice for them to depend on the (erroneous) delegatesFocus behavior.
As we rollout this fix, I will pay attention to potential regression reports.

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.

Stephen Chenney

unread,
Dec 3, 2024, 10:55:18 AM12/3/24
to Di Zhang, blink-dev
On Tue, Dec 3, 2024 at 10:47 AM Di Zhang <dizh...@chromium.org> wrote:
It is possible, although unlikely. The bug has a 23 stars (meaning people are running into it) and this fix makes us behave the same way as Webkit and Gecko.
If someone wants to make text inside a shadow DOM not selectable, they can still set the CSS user-select property to none. It would be bad practice for them to depend on the (erroneous) delegatesFocus behavior.
As we rollout this fix, I will pay attention to potential regression reports.

Thanks. That addresses my concerns. I can see 25 stars on the bug as a real signal in this context (i.e. not driven by social media).

Cheers,
Stephen.


To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
Reply all
Reply to author
Forward
0 new messages