Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/243387

Change subject: BookletLayout: Fix focus of page switching
......................................................................

BookletLayout: Fix focus of page switching

* Use document.activeElement to check if the page has focus
  as :focus doesn't work until a later event cycle.
* Create a PageLayout.focus method so subclasses can choose
  to focus something other than the first focusable element.

Bug: T114562
Change-Id: I6a439cb13e572adaee38258a03b8b2d1a560aa0c
---
M src/layouts/BookletLayout.js
M src/layouts/PageLayout.js
2 files changed, 11 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/87/243387/1

diff --git a/src/layouts/BookletLayout.js b/src/layouts/BookletLayout.js
index 456ef3f..39a2cba 100644
--- a/src/layouts/BookletLayout.js
+++ b/src/layouts/BookletLayout.js
@@ -196,8 +196,8 @@
                return;
        }
        // Only change the focus if is not already in the current page
-       if ( !page.$element.find( ':focus' ).length ) {
-               OO.ui.findFocusable( page.$element ).focus();
+       if ( !OO.ui.contains( page.$element[ 0 ], 
this.getElementDocument().activeElement, true ) ) {
+               page.focus();
        }
 };
 
diff --git a/src/layouts/PageLayout.js b/src/layouts/PageLayout.js
index be26e97..dc73236 100644
--- a/src/layouts/PageLayout.js
+++ b/src/layouts/PageLayout.js
@@ -136,3 +136,12 @@
                this.emit( 'active', this.active );
        }
 };
+
+/**
+ * Focus the page layout
+ *
+ * The default implementation just focuses the first focusable element in the 
page
+ */
+OO.ui.PageLayout.prototype.focus = function () {
+       OO.ui.findFocusable( this.$element ).focus();
+};

-- 
To view, visit https://gerrit.wikimedia.org/r/243387
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6a439cb13e572adaee38258a03b8b2d1a560aa0c
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to