<?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>258987</bug_id>
          
          <creation_ts>2023-07-07 10:48:27 -0700</creation_ts>
          <short_desc>Clicking a button, then calling `.focus()` on another button via JS causes `:focus-visible` to not fire.</short_desc>
          <delta_ts>2025-09-11 19:48:30 -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>CSS</component>
          <version>Safari 16</version>
          <rep_platform>Mac (Apple Silicon)</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="Konnor Rogers">konnor5456</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>agafvv</cc>
    
    <cc>akeerthi</cc>
    
    <cc>cory</cc>
    
    <cc>fotis.papadogeorgopoulos</cc>
    
    <cc>gwynne</cc>
    
    <cc>koivisto</cc>
    
    <cc>rego</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1965621</commentid>
    <comment_count>0</comment_count>
    <who name="Konnor Rogers">konnor5456</who>
    <bug_when>2023-07-07 10:48:27 -0700</bug_when>
    <thetext>## Problem

When implementing a focus-trap by using programmatic `.focus()` calls on elements, `:focus-visible` pseudo-selectors don&apos;t propagate to the element. Only `:focus` and `:focus-within`.

`:focus-visible` disappears after clicking a &lt;button&gt; and then calling `.focus()` in Safari 16.4

The above works as expected in Chrome 114.0.5735.198, Edge 114.0.1823.67, and Firefox 114.0.2 

## Reproduction

https://codepen.io/paramagicdev/pen/xxQXWbq?editors=1111

## Similar bugs

I think this may be a duplicate of: https://bugs.webkit.org/show_bug.cgi?id=246591

Based on the above bug, the issue may also have something to do with `e.preventDefault()`</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1966777</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-07-14 10:49:23 -0700</bug_when>
    <thetext>&lt;rdar://problem/112276014&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>