Bug 225147 - [selectors] :focus-visible and contenteditable
Summary: [selectors] :focus-visible and contenteditable
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
Keywords: InRadar
Depends on:
Blocks: 185859
  Show dependency treegraph
Reported: 2021-04-28 03:11 PDT by Manuel Rego Casasnovas
Modified: 2021-05-05 03:12 PDT (History)
2 users (show)

See Also:

Example (316 bytes, text/html)
2021-04-28 03:28 PDT, Manuel Rego Casasnovas
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel Rego Casasnovas 2021-04-28 03:11:03 PDT
This comes from a comment in a different bug:

There we were talking about the condition in Element::shouldAlwaysHaveFocusVisibleWhenFocused().
And we were wondering if we should use isRootEditableElement() instead of isContentEditable().

I'm attaching an example like this:
      :focus { border: solid thick magenta; }
      :focus-visible { background: cyan; } 
    <div id="wrapper" contenteditable>
      <div>Inner DIV</div>
      <div id="target" tabindex="0">Inner DIV with tabindex</div>
      <div>Another inner DIV</div>

Here the first time you click in DIV#target, the whole DIV#wrapper is focused. And the whole DIV#wrapper matches :focus-visible.
This time both isRootEditableElement() and isContentEditable() are true, because we're focusing DIV#wrapper.
The 2nd time we click in DIV#target, only DIV#target is focused, and only DIV#target matches :focus-visible.
Now isRootEditableElement() is false and isContentEditable() is true.

If we change the code to use isRootEditableElement(), then wewon't match :focus-visible in DIV#target in the 2nd click. So we'll be editing that element without matching :focus-visible which seems wrong.

Maybe the example should be different, or I'm missing some other combination.

Please Ryosuke share your thoughts. Thanks!
Comment 1 Manuel Rego Casasnovas 2021-04-28 03:28:48 PDT
Created attachment 427250 [details]
Comment 2 Radar WebKit Bug Importer 2021-05-05 03:12:14 PDT