Bartosz Dziewoński has uploaded a new change for review.

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

Change subject: SelectWidget: Improve focus behavior
......................................................................

SelectWidget: Improve focus behavior

If possible, only highlight an item when the widget (or one of the
options) gets focus, rather than select it. This matches the behavior
of arrow keys navigation.

Note that this is purely theoretical, as right now as far as I know
the only OptionWidget with 'highlightable' set is MenuOptionWidget,
and MenuSelectWidgets can't have focus anyway (they depend on being
attached to some other widget).

Change-Id: I456e041cf483458af49d40e1a05a5c92eb26becb
---
M src/widgets/SelectWidget.js
1 file changed, 14 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/96/290596/1

diff --git a/src/widgets/SelectWidget.js b/src/widgets/SelectWidget.js
index 73f94b7..dd757f9 100644
--- a/src/widgets/SelectWidget.js
+++ b/src/widgets/SelectWidget.js
@@ -155,16 +155,28 @@
  * @param {jQuery.Event} event
  */
 OO.ui.SelectWidget.prototype.onFocus = function ( event ) {
+       var item;
        if ( event.target === this.$element[ 0 ] ) {
                // This widget was focussed, e.g. by the user tabbing to it.
                // The styles for focus state depend on one of the items being 
selected.
                if ( !this.getSelectedItem() ) {
-                       this.selectItem( this.getFirstSelectableItem() );
+                       item = this.getFirstSelectableItem();
                }
        } else {
                // One of the options got focussed (and the event bubbled up 
here).
                // They can't be tabbed to, but they can be activated using 
accesskeys.
-               this.selectItem( this.getTargetItem( event ) );
+               item = this.getTargetItem( event );
+       }
+
+       if ( item ) {
+               if ( item.constructor.static.highlightable ) {
+                       this.highlightItem( item );
+               } else {
+                       this.selectItem( item );
+               }
+       }
+
+       if ( event.target !== this.$element[ 0 ] ) {
                this.$element.focus();
        }
 };

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I456e041cf483458af49d40e1a05a5c92eb26becb
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

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

Reply via email to