<?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>243289</bug_id>
          
          <creation_ts>2022-07-28 03:16:19 -0700</creation_ts>
          <short_desc>:focus-visible matches when an element is focused in an anchor’s click listener</short_desc>
          <delta_ts>2025-12-09 04:12:58 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>CSS</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</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>harry-moore</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>brian</cc>
    
    <cc>harry-moore</cc>
    
    <cc>ntim</cc>
    
    <cc>rego</cc>
    
    <cc>Rican7</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1887304</commentid>
    <comment_count>0</comment_count>
    <who name="">harry-moore</who>
    <bug_when>2022-07-28 03:16:19 -0700</bug_when>
    <thetext>When using a mouse to click an anchor which triggers a script that sets focus to another element, the focused element matches :focus-visible.

On a single page application this is really noticeable and arguably not desired behaviour.

See https://codepen.io/HazzMan2409/pen/rNdYNpa

Note this is very similar to this bug https://bugs.webkit.org/show_bug.cgi?id=236782

Maybe this issue occurs with other elements (not just anchors).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1888823</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-08-04 03:17:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/98113373&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2003546</commentid>
    <comment_count>2</comment_count>
    <who name="Brian Birtles">brian</who>
    <bug_when>2024-01-08 00:49:00 -0800</bug_when>
    <thetext>Not just clicking with a mouse, but tapping on iOS too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2164399</commentid>
    <comment_count>3</comment_count>
    <who name="">harry-moore</who>
    <bug_when>2025-12-09 04:11:46 -0800</bug_when>
    <thetext>I am closing this off because after looking into it this is not a bug.

A couple of notes:
* on iOS and macOS ports of WebKit, an anchor element does not get focus on pointing device click.
* :focus-visible should only match on script focus if the previously focused element matched :focus-visible. This is based on the spec guidelines which WebKit strives to implement -&gt; https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo

When loading a page and then clicking an anchor element like in the linked code pen, since the anchor element never gets focus, there is no previously focused element and so all bets are off. :focus-visible matching is acceptable!

If, however, the anchor is made focusable by adding a tabindex then :focus-visible should not match. This is the current behavior!</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>