v132 · dom
Fix Selection isCollapsed in Shadow DOM
Selection isCollapsed should return true if and only if the anchor and focus are the same. This should be true whether the selection starts/ends inside a light or a shadow tree. Currently, the Chrome implementation returns true if selection's anchor node is in a shadow tree, even if the selection itself is not collapsed. We fix this by removing the err
concepts
-
Shadow Selection isCollapsed
Selection.isCollapsed reports the right value across shadow boundaries. One less shadow-DOM papercut for editors.
-
inline toolbar
The real-world break: a Medium-style floating toolbar that needed isCollapsed=false to appear over shadow-rooted editors.
-
cross-tree cases
Four canonical selection topologies. For each: the v132 value, the spec value, and the pre-v132 buggy value. See exactly which scenarios were broken.
-
live readout
Real shadow-rooted custom element on the page. Select across it with shift-arrow keys and watch
selection.isCollapsed,anchorNode,focusNode, and the pre-v132 buggy version live.
why it shipped
The Chromium issue was opened in 2015 and has 13 stars. Many web developers have mentioned this bug being a pain point and having to work around it. For example, [1] and [2].