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

Commit a221d11

Browse files
committed
Another fix for appendToBody support: for some reason that I don't comprehend right now, the transclude function needs to be called before the appendToBody attribute is wire up. Otherwise the height measurement is incorrect when the the dropdown is opened (using the Bootstrap theme) because both the ui-select-match and the ui-select-choices elements are visible at the same time. I'd appreciate if anyone could explain this, but this change does the trick for me.
1 parent 47b55d1 commit a221d11

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/uiSelectDirective.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,32 @@ uis.directive('uiSelect',
162162
$document.off('click', onDocumentClick);
163163
});
164164

165+
// Move transcluded elements to their correct position in main template
166+
transcludeFn(scope, function(clone) {
167+
// See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html
168+
169+
// One day jqLite will be replaced by jQuery and we will be able to write:
170+
// var transcludedElement = clone.filter('.my-class')
171+
// instead of creating a hackish DOM element:
172+
var transcluded = angular.element('<div>').append(clone);
173+
174+
var transcludedMatch = transcluded.querySelectorAll('.ui-select-match');
175+
transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr
176+
transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes
177+
if (transcludedMatch.length !== 1) {
178+
throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length);
179+
}
180+
element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch);
181+
182+
var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices');
183+
transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr
184+
transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes
185+
if (transcludedChoices.length !== 1) {
186+
throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length);
187+
}
188+
element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices);
189+
});
190+
165191
// Support for appending the select field to the body when its open
166192
var appendToBody = scope.$eval(attrs.appendToBody);
167193
if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) {
@@ -222,32 +248,6 @@ uis.directive('uiSelect',
222248
element[0].style.top = '';
223249
element[0].style.width = originalWidth;
224250
}
225-
226-
// Move transcluded elements to their correct position in main template
227-
transcludeFn(scope, function(clone) {
228-
// See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html
229-
230-
// One day jqLite will be replaced by jQuery and we will be able to write:
231-
// var transcludedElement = clone.filter('.my-class')
232-
// instead of creating a hackish DOM element:
233-
var transcluded = angular.element('<div>').append(clone);
234-
235-
var transcludedMatch = transcluded.querySelectorAll('.ui-select-match');
236-
transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr
237-
transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes
238-
if (transcludedMatch.length !== 1) {
239-
throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length);
240-
}
241-
element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch);
242-
243-
var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices');
244-
transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr
245-
transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes
246-
if (transcludedChoices.length !== 1) {
247-
throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length);
248-
}
249-
element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices);
250-
});
251251
};
252252
}
253253
};

0 commit comments

Comments
 (0)