Commit 288e8c7c authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'issuable-sidebar-edit-button-field-focus' into 'master'

Fixed dropdown filter input not focusing after transition

Closes #33216

See merge request !12020
parents 4a228954 dfa4a440
...@@ -248,7 +248,7 @@ GitLabDropdown = (function() { ...@@ -248,7 +248,7 @@ GitLabDropdown = (function() {
return function(data) { return function(data) {
_this.fullData = data; _this.fullData = data;
_this.parseData(_this.fullData); _this.parseData(_this.fullData);
_this.focusTextInput(); _this.focusTextInput(true);
if (_this.options.filterable && _this.filter && _this.filter.input && _this.filter.input.val() && _this.filter.input.val().trim() !== '') { if (_this.options.filterable && _this.filter && _this.filter.input && _this.filter.input.val() && _this.filter.input.val().trim() !== '') {
return _this.filter.input.trigger('input'); return _this.filter.input.trigger('input');
} }
...@@ -728,8 +728,20 @@ GitLabDropdown = (function() { ...@@ -728,8 +728,20 @@ GitLabDropdown = (function() {
return [selectedObject, isMarking]; return [selectedObject, isMarking];
}; };
GitLabDropdown.prototype.focusTextInput = function() { GitLabDropdown.prototype.focusTextInput = function(triggerFocus = false) {
if (this.options.filterable) { this.filterInput.focus(); } if (this.options.filterable) {
$(':focus').blur();
this.dropdown.one('transitionend', () => {
this.filterInput.focus();
});
if (triggerFocus) {
// This triggers after a ajax request
// in case of slow requests, the dropdown transition could already be finished
this.dropdown.trigger('transitionend');
}
}
}; };
GitLabDropdown.prototype.addInput = function(fieldName, value, selectedObject) { GitLabDropdown.prototype.addInput = function(fieldName, value, selectedObject) {
......
---
title: Fixed dropdown filter input not focusing after transition
merge_request:
author:
...@@ -185,7 +185,7 @@ import '~/lib/utils/url_utility'; ...@@ -185,7 +185,7 @@ import '~/lib/utils/url_utility';
expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR)); expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR));
}); });
it('should focus on input when opening for the second time', () => { it('should focus on input when opening for the second time after transition', () => {
remoteCallback(); remoteCallback();
this.dropdownContainerElement.trigger({ this.dropdownContainerElement.trigger({
type: 'keyup', type: 'keyup',
...@@ -193,6 +193,7 @@ import '~/lib/utils/url_utility'; ...@@ -193,6 +193,7 @@ import '~/lib/utils/url_utility';
keyCode: ARROW_KEYS.ESC keyCode: ARROW_KEYS.ESC
}); });
this.dropdownButtonElement.click(); this.dropdownButtonElement.click();
this.dropdownContainerElement.trigger('transitionend');
expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR)); expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR));
}); });
}); });
...@@ -201,6 +202,7 @@ import '~/lib/utils/url_utility'; ...@@ -201,6 +202,7 @@ import '~/lib/utils/url_utility';
it('should focus input when passing array data to drop down', () => { it('should focus input when passing array data to drop down', () => {
initDropDown.call(this, false, true); initDropDown.call(this, false, true);
this.dropdownButtonElement.click(); this.dropdownButtonElement.click();
this.dropdownContainerElement.trigger('transitionend');
expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR)); expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR));
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment