Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit ffa1323

Browse files
author
Cory Stevens
committed
Add support for tabindex on searchInput
If the ui-select is in multiple mode, add the tabindex to the search input instead of the focusser.
1 parent e60561c commit ffa1323

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/select.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@
549549
var $select = ctrls[0];
550550
var ngModel = ctrls[1];
551551

552+
var searchInput = element.querySelectorAll('input.ui-select-search');
553+
552554
$select.multiple = angular.isDefined(attrs.multiple);
553555

554556
$select.onSelectCallback = $parse(attrs.onSelect);
@@ -628,7 +630,12 @@
628630
if(attrs.tabindex){
629631
//tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex
630632
attrs.$observe('tabindex', function(value) {
631-
focusser.attr("tabindex", value);
633+
//If we are using multiple, add tabindex to the search input
634+
if($select.multiple){
635+
searchInput.attr("tabindex", value);
636+
} else {
637+
focusser.attr("tabindex", value);
638+
}
632639
//Remove the tabindex on the parent so that it is not focusable
633640
element.removeAttr("tabindex");
634641
});

test/select.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ describe('ui-select tests', function() {
773773
if (attrs !== undefined) {
774774
if (attrs.disabled !== undefined) { attrsHtml += ' ng-disabled="' + attrs.disabled + '"'; }
775775
if (attrs.required !== undefined) { attrsHtml += ' ng-required="' + attrs.required + '"'; }
776+
if (attrs.tabindex !== undefined) { attrsHtml += ' tabindex="' + attrs.tabindex + '"'; }
776777
}
777778

778779
return compileTemplate(
@@ -818,6 +819,31 @@ describe('ui-select tests', function() {
818819
// $timeout.flush();
819820
});
820821

822+
it('should pass tabindex to searchInput', function() {
823+
var el = createUiSelectMultiple({tabindex: 5});
824+
var searchInput = el.find('.ui-select-search');
825+
826+
expect(searchInput.attr('tabindex')).toEqual('5');
827+
expect($(el).attr('tabindex')).toEqual(undefined);
828+
});
829+
830+
it('should pass tabindex to searchInput when tabindex is an expression', function() {
831+
scope.tabValue = 22;
832+
var el = createUiSelectMultiple({tabindex: '{{tabValue + 10}}'});
833+
var searchInput = el.find('.ui-select-search');
834+
835+
expect(searchInput.attr('tabindex')).toEqual('32');
836+
expect($(el).attr('tabindex')).toEqual(undefined);
837+
});
838+
839+
it('should not give searchInput a tabindex when ui-select does not have one', function() {
840+
var el = createUiSelectMultiple();
841+
var searchInput = el.find('.ui-select-search');
842+
843+
expect(searchInput.attr('tabindex')).toEqual(undefined);
844+
expect($(el).attr('tabindex')).toEqual(undefined);
845+
});
846+
821847
it('should update size of search input after removing an item', function() {
822848
scope.selection.selectedMultiple = [scope.people[4], scope.people[5]]; //Wladimir & Samantha
823849
var el = createUiSelectMultiple();

0 commit comments

Comments
 (0)