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

Commit e60561c

Browse files
author
Cory Stevens
committed
Add support for tabindex on focusser input
This change adds the ability to specify tabindex on the ui-select element and have it passed to the focusser input. The tabindex is removed from the ui-select div after it is applied to the focusser input.
1 parent 3b5c482 commit e60561c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/select.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,16 @@
624624

625625
//Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954
626626
var focusser = angular.element("<input ng-disabled='$select.disabled' class='ui-select-focusser ui-select-offscreen' type='text' aria-haspopup='true' role='button' />");
627+
628+
if(attrs.tabindex){
629+
//tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex
630+
attrs.$observe('tabindex', function(value) {
631+
focusser.attr("tabindex", value);
632+
//Remove the tabindex on the parent so that it is not focusable
633+
element.removeAttr("tabindex");
634+
});
635+
}
636+
627637
$compile(focusser)(scope);
628638
$select.focusser = focusser;
629639

test/select.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe('ui-select tests', function() {
6666
if (attrs.disabled !== undefined) { attrsHtml += ' ng-disabled="' + attrs.disabled + '"'; }
6767
if (attrs.required !== undefined) { attrsHtml += ' ng-required="' + attrs.required + '"'; }
6868
if (attrs.theme !== undefined) { attrsHtml += ' theme="' + attrs.theme + '"'; }
69+
if (attrs.tabindex !== undefined) { attrsHtml += ' tabindex="' + attrs.tabindex + '"'; }
6970
}
7071

7172
return compileTemplate(
@@ -204,7 +205,28 @@ describe('ui-select tests', function() {
204205

205206
el.find(".ui-select-toggle").click();
206207
expect($select.open).toEqual(false);
208+
});
209+
210+
it('should pass tabindex to focusser', function() {
211+
var el = createUiSelect({tabindex: 5});
212+
213+
expect($(el).find('.ui-select-focusser').attr('tabindex')).toEqual('5');
214+
expect($(el).attr('tabindex')).toEqual(undefined);
215+
});
216+
217+
it('should pass tabindex to focusser when tabindex is an expression', function() {
218+
scope.tabValue = 22;
219+
var el = createUiSelect({tabindex: '{{tabValue + 10}}'});
220+
221+
expect($(el).find('.ui-select-focusser').attr('tabindex')).toEqual('32');
222+
expect($(el).attr('tabindex')).toEqual(undefined);
223+
});
224+
225+
it('should not give focusser a tabindex when ui-select does not have one', function() {
226+
var el = createUiSelect();
207227

228+
expect($(el).find('.ui-select-focusser').attr('tabindex')).toEqual(undefined);
229+
expect($(el).attr('tabindex')).toEqual(undefined);
208230
});
209231

210232
it('should be disabled if the attribute says so', function() {

0 commit comments

Comments
 (0)