<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>255149</bug_id>
          
          <creation_ts>2023-04-07 07:09:56 -0700</creation_ts>
          <short_desc>elements with CSS display:contents are not focusable</short_desc>
          <delta_ts>2026-04-27 00:25:18 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>Safari 16</version>
          <rep_platform>Mac (Intel)</rep_platform>
          <op_sys>macOS 13</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="L. David Baron">dbaron</reporter>
          <assigned_to name="Ahmad Saleem">ahmad.saleem792</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>aroselli</cc>
    
    <cc>cfleizach</cc>
    
    <cc>cyb.ai.815</cc>
    
    <cc>jcraig</cc>
    
    <cc>jensimmons</cc>
    
    <cc>koivisto</cc>
    
    <cc>mike</cc>
    
    <cc>rniwa</cc>
    
    <cc>tyler_w</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1947270</commentid>
    <comment_count>0</comment_count>
    <who name="L. David Baron">dbaron</who>
    <bug_when>2023-04-07 07:09:56 -0700</bug_when>
    <thetext>This bug is based on the conclusion in https://github.com/w3c/csswg-drafts/issues/2632 (and was also discussed a bit in https://github.com/whatwg/html/issues/1837 ).  In WebKit, elements with display: contents are not currently focusable, but they should be.

This behavior currently matches other browsers.  However, I think this behavior is problematic because elements with display:contents are exposed to assistive technology as having their normal roles, and the contract for the meaning of accessibility roles includes support for certain role-specific keyboard interactions which often include focusability.  So I think it&apos;s important that the exposure to AT (as agreed in the CSSWG in https://github.com/w3c/csswg-drafts/issues/2355 and I believe implemented in WebKit in https://bugs.webkit.org/show_bug.cgi?id=243486 ) match the focusability, which it currently does not. 

Steps to reproduce:
 1. load https://cdpn.io/aardrian/debug/NWqbggX (taken from two of the Gecko/Chromium bugs below)
 2. press Option+Tab to cycle through buttons

Expected results: focus moves through all buttons (although perhaps no visual indication of focus on the display:contents button)

Actual results: focus skips the display:contents button

Parallel Chromium and Gecko bugs are:
https://bugs.chromium.org/p/chromium/issues/detail?id=1366037
https://bugzilla.mozilla.org/show_bug.cgi?id=1553549
https://bugzilla.mozilla.org/show_bug.cgi?id=1791648

I have a change to Chromium to fix this (though I haven&apos;t merged it yet, partly out of concern for whether other browsers are willing to match):
https://chromium-review.googlesource.com/c/chromium/src/+/3910374</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1948776</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-04-14 07:10:15 -0700</bug_when>
    <thetext>&lt;rdar://problem/108048437&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1983482</commentid>
    <comment_count>2</comment_count>
    <who name="Adrian Roselli">aroselli</who>
    <bug_when>2023-10-07 13:52:46 -0700</bug_when>
    <thetext>Confirmed this bug persists in Safari 17 (macOS 14).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1983485</commentid>
    <comment_count>3</comment_count>
    <who name="Adrian Roselli">aroselli</who>
    <bug_when>2023-10-07 14:30:44 -0700</bug_when>
    <thetext>And confirmed the bug persists in Safari TP 180 (Safari 17.4 beta).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1983709</commentid>
    <comment_count>4</comment_count>
    <who name="Jen Simmons">jensimmons</who>
    <bug_when>2023-10-09 09:42:07 -0700</bug_when>
    <thetext>Adrian, this is still &quot;a bug&quot; because the standards questions have not been settled yet. There&apos;s not agreement on how browsers should behave. That needs to be decided before any browser can conform to the decisions.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1983710</commentid>
    <comment_count>5</comment_count>
    <who name="Adrian Roselli">aroselli</who>
    <bug_when>2023-10-09 10:00:32 -0700</bug_when>
    <thetext>Agreed it is a bug (no quotes) and also agree that OP&apos;s request for position and standards clarity are blockers.

I encourage all browsers (and their representatives in the standards bodies) to settle this so users don&apos;t have to wait any longer.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2204560</commentid>
    <comment_count>6</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-04-26 00:38:05 -0700</bug_when>
    <thetext>This fixes it in WebKit:

bool Element::hasFocusableStyle() const
{
    auto isFocusableStyle = [](const RenderStyle* style) {
        return style &amp;&amp; style-&gt;display().doesGenerateBox()
            &amp;&amp; style-&gt;visibility() == Visibility::Visible &amp;&amp; !style-&gt;effectiveInert()
            &amp;&amp; (style-&gt;usedContentVisibility() != ContentVisibility::Hidden || style-&gt;contentVisibility() != ContentVisibility::Visible);
    };

    if (renderStyle())
        return isFocusableStyle(renderStyle());

    // Compute style in yet unstyled subtree without resolving full style.
    CheckedPtr style = const_cast&lt;Element&amp;&gt;(*this).resolveComputedStyle(ResolveComputedStyleMode::RenderedOnly);
    return isFocusableStyle(style.get());
}

Changing:

 return style &amp;&amp; style-&gt;display().doesGenerateBox()

to:

return style &amp;&amp; style-&gt;display() != Style::DisplayType::None

It fixes both - https://wpt.fyi/results/css/css-display?label=master&amp;label=experimental&amp;aligned&amp;q=display-contents-focus</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2204666</commentid>
    <comment_count>7</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2026-04-26 13:47:56 -0700</bug_when>
    <thetext>That seems like a reasonable change to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2204795</commentid>
    <comment_count>8</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-04-27 00:25:18 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/63669</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>