Delay the auto focus of the submit button
authorAlexander Ebert <ebert@woltlab.com>
Wed, 29 Jun 2022 13:47:47 +0000 (15:47 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 29 Jun 2022 13:47:47 +0000 (15:47 +0200)
Safari delays the execution of the `blur` event on the document which causes the focus shift to happen too early.

Delaying it by two event cycles are enough to provide a consistent experience and to avoid conflicts with the focus trap.

See https://www.woltlab.com/community/thread/296069-best%C3%A4tigung-bei-installation-von-paket-%C3%BCber-entwickler-werkzeuge-nicht-direkt-pe/

ts/WoltLabSuite/Core/Ui/Confirmation.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Confirmation.js

index 5de324c8c372e748b565fce4e96426c747845be7..90bdb6ff0b49498da40ede860127a080fd67b85b 100644 (file)
@@ -122,8 +122,10 @@ class UiConfirmation implements DialogCallbackObject {
    * Sets the focus on the confirm button on dialog open for proper keyboard support.
    */
   _onShow(): void {
-    this.confirmButton.blur();
-    this.confirmButton.focus();
+    window.setTimeout(() => {
+      this.confirmButton.blur();
+      this.confirmButton.focus();
+    }, 1);
   }
 
   _dialogSetup(): ReturnType<DialogCallbackSetup> {
index f2d59027e41424bbdc11e82f3675cb8cdacedc53..193fce76efb8a74a0d13f4a75fdd78db1a5987fc 100644 (file)
@@ -93,8 +93,10 @@ define(["require", "exports", "tslib", "../Core", "../Language", "./Dialog"], fu
          * Sets the focus on the confirm button on dialog open for proper keyboard support.
          */
         _onShow() {
-            this.confirmButton.blur();
-            this.confirmButton.focus();
+            window.setTimeout(() => {
+                this.confirmButton.blur();
+                this.confirmButton.focus();
+            }, 1);
         }
         _dialogSetup() {
             return {