Skip to content

Commit 96714d2

Browse files
author
Tomas Kirda
committed
Add inner container, so that styling can be more flexible.
1 parent 6a9c2ca commit 96714d2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/jquery.autocomplete.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
that.onChange = null;
9494
that.isLocal = false;
9595
that.suggestionsContainer = null;
96+
that.innerContainer = null;
9697
that.options = $.extend({}, defaults, options);
9798
that.classes = {
9899
selected: 'autocomplete-selected',
@@ -126,7 +127,8 @@
126127
suggestionSelector = '.' + that.classes.suggestion,
127128
selected = that.classes.selected,
128129
options = that.options,
129-
container;
130+
container,
131+
innerContainer;
130132

131133
// Remove autocomplete attribute to prevent native suggestions:
132134
that.element.setAttribute('autocomplete', 'off');
@@ -138,12 +140,13 @@
138140
}
139141
};
140142

141-
that.suggestionsContainer = Autocomplete.utils.createNode('<div class="' + options.containerClass + '" style="position: absolute; display: none;"></div>');
143+
that.suggestionsContainer = Autocomplete.utils.createNode('<div class="' + options.containerClass + '" style="position: absolute; display: none;"><div class="autocomplete-inner"></div></div>');
142144

143145
container = $(that.suggestionsContainer);
144-
145146
container.appendTo(options.appendTo);
146147

148+
that.innerContainer = $('.autocomplete-inner', container);
149+
147150
// Only set width if it was provided:
148151
if (options.width !== 'auto') {
149152
container.width(options.width);
@@ -473,6 +476,7 @@
473476
className = that.classes.suggestion,
474477
classSelected = that.classes.selected,
475478
container = $(that.suggestionsContainer),
479+
innerContainer = that.innerContainer,
476480
html = '',
477481
width;
478482

@@ -490,13 +494,14 @@
490494
container.width(width > 0 ? width : 300);
491495
}
492496

493-
container.html(html).show();
497+
innerContainer.html(html);
498+
container.show();
494499
that.visible = true;
495500

496501
// Select first value by default:
497502
if (that.options.autoSelectFirst) {
498503
that.selectedIndex = 0;
499-
container.children().first().addClass(classSelected);
504+
innerContainer.children().first().addClass(classSelected);
500505
}
501506

502507
that.findBestHint();

0 commit comments

Comments
 (0)