Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/200640
Change subject: Fix focus on value field on property select ...................................................................... Fix focus on value field on property select With I6e694dd and possibly other recent snakview changes, keydown event now occurs after entityselectorselected. This meant that _tabToValueView is not set yet when entityselectorselected is executed and focus is never then set to the value input. I suppose perhaps this worked before because this check and the focus happened inside "self.options.entityStore.get( entityId ).done" so the timing worked. This allows focus to be set on tab or enter keydown or select. Bug: T93864 Change-Id: Id386edf0942f2378c11e24528a2957316099c91b --- M lib/resources/jquery.wikibase/snakview/snakview.js 1 file changed, 39 insertions(+), 53 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/40/200640/1 diff --git a/lib/resources/jquery.wikibase/snakview/snakview.js b/lib/resources/jquery.wikibase/snakview/snakview.js index d4ceb37..c870021 100644 --- a/lib/resources/jquery.wikibase/snakview/snakview.js +++ b/lib/resources/jquery.wikibase/snakview/snakview.js @@ -121,14 +121,6 @@ _isInEditMode: false, /** - * Caching whether to move the focus from the `Property` input to the value input after pressing - * the TAB key. - * @property {boolean} - * @private - */ - _tabToValueView: false, - - /** * Whether then `snakview`'s value is regarded "valid" at the moment. * @property {boolean} * @private @@ -247,9 +239,6 @@ type: 'property' } ) .prop( 'placeholder', mw.msg( 'wikibase-snakview-property-input-placeholder' ) ) - .on( 'blur', function( event ) { - self._tabToValueView = false; - } ) .on( 'eachchange', function( event, oldValue ) { // remove out-dated variations if( self._variation ) { @@ -259,27 +248,47 @@ self._trigger( 'change' ); } } ) - .on( 'entityselectorselected', function( e, entityId ) { - // Display spinner as long as the ValueView is loading: - self.$snakValue.empty().append( - $( '<div/>' ).append( $( '<span/>' ).addClass( 'mw-small-spinner' ) ) - ); - - self.updateVariation(); - self.drawSnakTypeSelector(); - self.drawVariation(); - - self._trigger( 'change' ); - - // Since it takes a while for the value view to gather its data from the API, - // the property might not be valid anymore aborting the rendering of the value - // view. - if( self._tabToValueView && self._variation ) { - $( self._variation ).one( 'afterdraw', function() { - self._variation.focus(); - } ); + .on( 'keydown', function( event ) { + // When pressing TAB, ENTER or clicking in the property input element while the value + // input element does not yet exist, we assume that the user wants to + // auto-complete/select the currently suggested property and tab into the value + // element. Since the API needs to be queried to construct the correct value input, + // the intended action needs to be cached and triggered as soon as the value input + // has been created. + if ( event.keyCode === $.ui.keyCode.TAB || event.keyCode === $.ui.keyCode.ENTER ) { + self._selectProperty(); } + } ) + .on( 'entityselectorselected', function( event, entityId ) { + self._selectProperty(); } ); + }, + + /** + * @private + */ + _selectProperty: function() { + var self = this; + + // Display spinner as long as the ValueView is loading: + this.$snakValue.empty().append( + $( '<div/>' ).append( $( '<span/>' ).addClass( 'mw-small-spinner' ) ) + ); + + this.updateVariation(); + this.drawSnakTypeSelector(); + this.drawVariation(); + + this._trigger( 'change' ); + + // Since it takes a while for the value view to gather its data from the API, + // the property might not be valid anymore aborting the rendering of the value + // view. + if ( this._variation ) { + $( this._variation ).one( 'afterdraw', function() { + self._variation.focus(); + } ); + } }, /** @@ -305,29 +314,6 @@ var self = this; this._isInEditMode = true; - - this.element.on( 'keydown.' + this.widgetName, function( event ) { - if ( self.options.disabled ) { - return; - } - - var propertySelector = self._getPropertySelector(); - - if ( event.keyCode === $.ui.keyCode.TAB && !self._variation ) { - event.stopPropagation(); - // When pressing TAB in the property input element while the value input element - // does not yet exist, we assume that the user wants to auto-complete/select the - // currently suggested property and tab into the value element. Since the API needs - // to be queried to construct the correct value input, the intended action needs to - // be cached and triggered as soon as the value input has been created. - if ( propertySelector && event.target === propertySelector.element[0] ) { - if( self._getPropertySelector().selectedEntity() ) { - self._tabToValueView = true; - event.preventDefault(); - } - } - } - } ); if( this._variation ) { $( this._variation ).one( 'afterstartediting', function() { -- To view, visit https://gerrit.wikimedia.org/r/200640 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id386edf0942f2378c11e24528a2957316099c91b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: wmf/1.25wmf22 Gerrit-Owner: Aude <aude.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits