@@ -162,6 +162,32 @@ uis.directive('uiSelect',
162
162
$document . off ( 'click' , onDocumentClick ) ;
163
163
} ) ;
164
164
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
+
165
191
// Support for appending the select field to the body when its open
166
192
var appendToBody = scope . $eval ( attrs . appendToBody ) ;
167
193
if ( appendToBody !== undefined ? appendToBody : uiSelectConfig . appendToBody ) {
@@ -181,7 +207,8 @@ uis.directive('uiSelect',
181
207
}
182
208
183
209
// Hold on to a reference to the .ui-select-container element for appendToBody support
184
- var placeholder = null ;
210
+ var placeholder = null ,
211
+ originalWidth = '' ;
185
212
186
213
function positionDropdown ( ) {
187
214
// Remember the absolute position of the element
@@ -193,6 +220,10 @@ uis.directive('uiSelect',
193
220
placeholder [ 0 ] . style . height = offset . height + 'px' ;
194
221
element . after ( placeholder ) ;
195
222
223
+ // Remember the original value of the element width inline style, so it can be restored
224
+ // when the dropdown is closed
225
+ originalWidth = element [ 0 ] . style . width ;
226
+
196
227
// Now move the actual dropdown element to the end of the body
197
228
$document . find ( 'body' ) . append ( element ) ;
198
229
@@ -215,34 +246,8 @@ uis.directive('uiSelect',
215
246
element [ 0 ] . style . position = '' ;
216
247
element [ 0 ] . style . left = '' ;
217
248
element [ 0 ] . style . top = '' ;
218
- element [ 0 ] . style . width = '' ;
249
+ element [ 0 ] . style . width = originalWidth ;
219
250
}
220
-
221
- // Move transcluded elements to their correct position in main template
222
- transcludeFn ( scope , function ( clone ) {
223
- // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html
224
-
225
- // One day jqLite will be replaced by jQuery and we will be able to write:
226
- // var transcludedElement = clone.filter('.my-class')
227
- // instead of creating a hackish DOM element:
228
- var transcluded = angular . element ( '<div>' ) . append ( clone ) ;
229
-
230
- var transcludedMatch = transcluded . querySelectorAll ( '.ui-select-match' ) ;
231
- transcludedMatch . removeAttr ( 'ui-select-match' ) ; //To avoid loop in case directive as attr
232
- transcludedMatch . removeAttr ( 'data-ui-select-match' ) ; // Properly handle HTML5 data-attributes
233
- if ( transcludedMatch . length !== 1 ) {
234
- throw uiSelectMinErr ( 'transcluded' , "Expected 1 .ui-select-match but got '{0}'." , transcludedMatch . length ) ;
235
- }
236
- element . querySelectorAll ( '.ui-select-match' ) . replaceWith ( transcludedMatch ) ;
237
-
238
- var transcludedChoices = transcluded . querySelectorAll ( '.ui-select-choices' ) ;
239
- transcludedChoices . removeAttr ( 'ui-select-choices' ) ; //To avoid loop in case directive as attr
240
- transcludedChoices . removeAttr ( 'data-ui-select-choices' ) ; // Properly handle HTML5 data-attributes
241
- if ( transcludedChoices . length !== 1 ) {
242
- throw uiSelectMinErr ( 'transcluded' , "Expected 1 .ui-select-choices but got '{0}'." , transcludedChoices . length ) ;
243
- }
244
- element . querySelectorAll ( '.ui-select-choices' ) . replaceWith ( transcludedChoices ) ;
245
- } ) ;
246
251
} ;
247
252
}
248
253
} ;
0 commit comments