<?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>236322</bug_id>
          
          <creation_ts>2022-02-08 12:48:20 -0800</creation_ts>
          <short_desc>Dialog&apos;s &quot;previously focused element&quot; and focus-visible</short_desc>
          <delta_ts>2022-02-15 09:30:38 -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>DOM</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Mac (Intel)</rep_platform>
          <op_sys>macOS 12</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>
          
          <blocked>84635</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Darin Senneff">darin.senneff</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>koivisto</cc>
    
    <cc>ntim</cc>
    
    <cc>rego</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1838838</commentid>
    <comment_count>0</comment_count>
    <who name="Darin Senneff">darin.senneff</who>
    <bug_when>2022-02-08 12:48:20 -0800</bug_when>
    <thetext>When closing a &lt;dialog&gt; element, focus is only moved back to the &quot;previously focused element&quot; if a keyboard was used to initially show the dialog. I&apos;m assuming this has to do with the focus-visible algorithm, as a click doesn&apos;t normally put visible focus on a button. 

But because the &lt;dialog&gt; autofocuses a button upon being opened, it&apos;s possible users will then use the keyboard to close the modal rather than click – by pressing the ENTER, SPACE, or ESC keys. In these cases where the user has changed their input method from click/tap to keyboard, should the previous element now receive focus? 

I think regardless of the input method used to close a modal, focus should be placed on the previous element to help re-orient the user. But at minimum I think it should in cases where a keyboard was used to close the &lt;dialog&gt;.

Looking at the spec&apos;s dialog focusing steps, this edge case seems beyond that. But think there&apos;s value in it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1839152</commentid>
    <comment_count>1</comment_count>
    <who name="Manuel Rego Casasnovas">rego</who>
    <bug_when>2022-02-09 07:51:37 -0800</bug_when>
    <thetext>Hi, thanks for the bug report.

If you&apos;re testing this on Mac, &lt;button&gt; are not mouse focusable on Mac (see https://bugs.webkit.org/show_bug.cgi?id=229895 for more details).

So I guess that when you close the dialog, if it was opened by a button, it&apos;s not going to be focused when you close it.

I&apos;ve tested on WebKitGTK (Linux), and the button that opens the dialog gets focused when I close it.

If the problem is unrelated to the buttons not being click focusable on Mac, could you please create a test case reproducing the issue?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1839156</commentid>
    <comment_count>2</comment_count>
    <who name="Darin Senneff">darin.senneff</who>
    <bug_when>2022-02-09 08:01:50 -0800</bug_when>
    <thetext>Yup, I get the non-focusable button if the &lt;dialog&gt; is opened and closed with a mouse. And that if its opened and closed with a keyboard that the button does get focus. 

But what if the &lt;dialog&gt; is opened with a mouse but closed with a keyboard? Since the element autofocuses a button upon opening (and can be closed with the ESC key), it&apos;s likely that some users will switch to a keyboard after originally opening the &lt;dialog&gt; with their mouse/finger. In those cases, doesn&apos;t it make sense to put keyboard focus to the button?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1841753</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-02-15 09:30:38 -0800</bug_when>
    <thetext>&lt;rdar://problem/88969727&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>