Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat(select): add psuedo-element to make auto complete work
Browse files Browse the repository at this point in the history
closes #1801
  • Loading branch information
rschmukler committed Apr 1, 2015
1 parent 38e8196 commit aa440ef
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $interpolate, $compile,

return {
restrict: 'E',
require: ['mdSelect', 'ngModel'],
require: ['mdSelect', 'ngModel', '?^form'],
compile: compile,
controller: function() { } // empty placeholder controller to be initialized in link
};
Expand Down Expand Up @@ -110,6 +110,20 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $interpolate, $compile,
);
}

if (attr.name) {
var autofillClone = angular.element('<select style="position: absolute; z-index: -1">');

This comment has been minimized.

Copy link
@rschmukler

rschmukler Apr 2, 2015

Author Contributor

add class visually-hidden, attribute aria-hidden="true" and tabindex="-1"

autofillClone.attr({
'name': '.' + attr.name,
'ng-model': attr.ngModel
});
var opts = element.find('md-option');
angular.forEach(opts, function(el) {
var el = angular.element('<option value="' + el.getAttribute('value') + '">' + el.innerHTML + '</option>');
autofillClone.append(el);
});
element.parent().append(autofillClone);
}

// Use everything that's left inside element.contents() as the contents of the menu
var selectTemplate = '<div class="md-select-menu-container">' +
'<md-select-menu ' +
Expand All @@ -127,11 +141,18 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $interpolate, $compile,

var mdSelectCtrl = ctrls[0];
var ngModel = ctrls[1];
var formCtrl = ctrls[2];

var labelEl = element.find('md-select-label');
var customLabel = labelEl.text().length !== 0;
var selectContainer, selectScope, selectMenuCtrl;
createSelect();

if (attr.name && formCtrl) {
var selectEl = element.parent()[0].querySelector('select[name=".' + attr.name + '"]')
formCtrl.$removeControl(angular.element(selectEl).controller());
}

var originalRender = ngModel.$render;
ngModel.$render = function() {
originalRender();
Expand Down

0 comments on commit aa440ef

Please sign in to comment.