-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Highlight tags first in results even if other selections exist (#5812)
* refactor: check for unselected options when using tags and highlight that option first * Switch to using a decorator for highlighting tags This switches the implementation to use a decorator which is only added when the `tags` option is set during initialization. Functionally it has no change on the effect but it allows for the logic to be more isolated. In the end it just keeps it more organized and works towards cutting back on what is included in the core results. This also changes the call for setting the `select2-data-tag` attribute to properly set the attribute as a string instead of relying on the boolean to string conversion. * Fix tabbing in newly added decorator * Add tests for tag focusing in results Co-authored-by: Kevin Brown <kevin@kevin-brown.com>
- Loading branch information
1 parent
5e8699d
commit af79c80
Showing
4 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
define([ | ||
'../utils' | ||
], function (Utils) { | ||
function TagsSearchHighlight () { } | ||
|
||
TagsSearchHighlight.prototype.highlightFirstItem = function (decorated) { | ||
var $options = this.$results | ||
.find( | ||
'.select2-results__option--selectable' + | ||
':not(.select2-results__option--selected)' | ||
); | ||
|
||
if ($options.length > 0) { | ||
var $firstOption = $options.first(); | ||
var data = Utils.GetData($firstOption[0], 'data'); | ||
var firstElement = data.element; | ||
|
||
if (firstElement && firstElement.getAttribute) { | ||
if (firstElement.getAttribute('data-select2-tag') === 'true') { | ||
$firstOption.trigger('mouseenter'); | ||
|
||
return; | ||
} | ||
} | ||
} | ||
|
||
decorated.call(this); | ||
}; | ||
|
||
return TagsSearchHighlight; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters