diff --git a/src/components/autocomplete/AutoComplete.vue b/src/components/autocomplete/AutoComplete.vue index 984f29917..8beb88c8d 100755 --- a/src/components/autocomplete/AutoComplete.vue +++ b/src/components/autocomplete/AutoComplete.vue @@ -22,9 +22,9 @@ @@ -174,6 +174,9 @@ export default { getOptionIndex(index, fn) { return this.virtualScrollerDisabled ? index : (fn && fn(index)['index']); }, + getOptionRenderKey(option) { + return this.getItemContent(option); + }, getOptionGroupRenderKey(optionGroup) { return ObjectUtils.resolveFieldData(optionGroup, this.optionGroupLabel); }, @@ -191,8 +194,7 @@ export default { this.bindResizeListener(); if (this.autoHighlight && this.suggestions && this.suggestions.length) { - let itemList = DomHandler.findSingle(this.overlay, '.p-autocomplete-items'); - DomHandler.addClass(itemList.firstElementChild, 'p-highlight'); + DomHandler.addClass(this.list.firstElementChild, 'p-highlight'); } }, onOverlayLeave() { @@ -394,7 +396,7 @@ export default { }, onKeyDown(event) { if (this.overlayVisible) { - let highlightItem = DomHandler.findSingle(this.overlay, 'li.p-highlight'); + let highlightItem = DomHandler.findSingle(this.list, 'li.p-highlight'); switch(event.which) { //down @@ -404,11 +406,11 @@ export default { if (nextElement) { DomHandler.addClass(nextElement, 'p-highlight'); DomHandler.removeClass(highlightItem, 'p-highlight'); - DomHandler.scrollInView(this.overlay, nextElement); + nextElement.scrollIntoView({ block: 'nearest', inline: 'start' }); } } else { - highlightItem = this.overlay.firstElementChild.firstElementChild; + highlightItem = this.list.firstElementChild; if (DomHandler.hasClass(highlightItem, 'p-autocomplete-item-group')) { highlightItem = this.findNextItem(highlightItem); } @@ -428,7 +430,7 @@ export default { if (previousElement) { DomHandler.addClass(previousElement, 'p-highlight'); DomHandler.removeClass(highlightItem, 'p-highlight'); - DomHandler.scrollInView(this.overlay, previousElement); + previousElement.scrollIntoView({ block: 'nearest', inline: 'start' }); } } @@ -492,7 +494,7 @@ export default { this.selectItem(event, this.getOptionGroupChildren(optionGroup)[item.dataset.index]); } else { - this.selectItem(event, this.suggestions[DomHandler.index(item)]); + this.selectItem(event, this.suggestions[item.dataset.index]); } }, findNextItem(item) { @@ -553,6 +555,10 @@ export default { overlayRef(el) { this.overlay = el; }, + listRef(el, contentRef) { + this.list = el; + contentRef && contentRef(el); // for virtualScroller + }, virtualScrollerRef(el) { this.virtualScroller = el; },