Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/components/autocomplete/autocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,81 @@ describe('<md-autocomplete>', function() {
expect(input[0].getAttribute('aria-activedescendant')).toBe('md-option-' + ctrl.id + '-1');
});

it('should not retain the position of the scroll after panel is reopened', function() {
var template =
'<md-autocomplete' +
' md-selected-item="selectedItem"' +
' md-search-text="searchText"' +
' md-items="item in match(searchText)"' +
' md-item-text="item.display"' +
' placeholder="placeholder"' +
' md-min-length="0"' +
' md-escape-options="clear"' +
' md-autoselect="false">' +
' <span md-highlight-text="searchText">{{item.display}}</span>' +
'</md-autocomplete>';
var items = [];
for (var i = 0; i < 20; i++) {
items.push({ display: 'f' + i});
}
var scope = createScope(items);
var element = compile(template, scope);
var ctrl = element.controller('mdAutocomplete');
var input = element.find('input');
// Run our initial flush
$timeout.flush();

// Initial state
expect(ctrl.index).toBe(-1);
expect(ctrl.hidden).toBe(true);
expect(ctrl.activeOption).toBe(null);

ctrl.focus();
waitForVirtualRepeat(element);

// After getting focus
expect(ctrl.hidden).toBe(false);
expect(ctrl.index).toBe(-1);
expect(ctrl.activeOption).toBe(null);

ctrl.blur();

// After loosing focus
expect(ctrl.hidden).toBe(true);

ctrl.focus();
waitForVirtualRepeat();

// After getting focus again
expect(ctrl.hidden).toBe(false);
expect(ctrl.index).toBe(-1);
expect(ctrl.activeOption).toBe(null);

for (var j = 0; j < 10; j++){
ctrl.keydown(keydownEvent($mdConstant.KEY_CODE.DOWN_ARROW));
}
$material.flushInterimElement();

// After highlighting the 10th element
expect(ctrl.hidden).toBe(false);
expect(ctrl.index).toBe(9);
expect(ctrl.activeOption).toBe('md-option-' + ctrl.id + '-9');

ctrl.blur();

// After loosing focus
expect(ctrl.hidden).toBe(true);
ctrl.focus();
waitForVirtualRepeat();

// After getting focus again
expect(ctrl.hidden).toBe(false);
expect(ctrl.index).toBe(-1);
expect(ctrl.activeOption).toBe(null);

element.remove();
});

it('should set activeOption when autoselect is on', function() {
var template =
'<md-autocomplete' +
Expand Down
6 changes: 5 additions & 1 deletion src/components/autocomplete/js/autocompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
scrollContainerElement.on('touchstart touchmove touchend', stopPropagation);
}
}
$mdUtil.nextTick(updateActiveOption);
ctrl.index = getDefaultIndex();
$mdUtil.nextTick(function() {
updateActiveOption();
updateScroll();
});
}
} else if (hidden && !oldHidden) {
if ($mdUtil.isIos) {
Expand Down