Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 71c8514

Browse files
guerganamicgro42lucaswerkmeister
authored
Fix Lookup menu navigation index reset issue on arrow down (#656)
Bug: T324743 Co-authored-by: Michael Große <[email protected]> Co-authored-by: Lucas Werkmeister <[email protected]>
1 parent 99330af commit 71c8514

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

vue-components/src/components/OptionsMenu.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ export default Vue.extend( {
193193
watch: {
194194
async menuItems(): Promise<void> {
195195
await this.$nextTick();
196-
this.keyboardHoveredItemIndex = this.selectedItemIndex;
196+
if ( this.selectedItemIndex > -1 ) {
197+
this.keyboardHoveredItemIndex = this.selectedItemIndex;
198+
}
197199
this.resizeMenu();
198200
},
199201
keyboardHoveredItemIndex( hoveredIndex: number ): void {

vue-components/stories/Lookup.stories.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Lookup from '@/components/Lookup';
22
import Icon from '@/components/Icon';
3-
import { Component } from 'vue';
43
import { MenuItem } from '@/components/MenuItem';
4+
import { Component } from 'vue';
55

66
export default {
77
component: Lookup,
@@ -67,6 +67,24 @@ const vegetableItems = [
6767
},
6868
];
6969

70+
const itemsToAddOnScroll = [
71+
{
72+
label: 'passionfruit',
73+
description: 'sour sweet tropical fruit',
74+
value: 'Q165449',
75+
},
76+
{
77+
label: 'jackfruit',
78+
description: 'edible fruit of the jack tree',
79+
value: 'Q16136843',
80+
},
81+
{
82+
label: 'sweet potato',
83+
description: 'a potato like root vegetable with a sweet taste',
84+
value: 'Q37937',
85+
},
86+
];
87+
7088
export function all(): Component {
7189
return {
7290
components: { Lookup, Icon },
@@ -75,21 +93,32 @@ export function all(): Component {
7593
search: '',
7694
selectedItem: null,
7795
visibleItems: null,
96+
menuVegetableItems: vegetableItems,
7897
};
7998
},
8099
computed: {
81-
menuItems(): MenuItem[] {
82-
return vegetableItems.filter( ( item ) => item.label.includes( this.search ) );
100+
menuItems: {
101+
get(): MenuItem[] {
102+
return this.menuVegetableItems.filter( ( item ) => item.label.includes( this.search ) );
103+
},
104+
set( newMenuItems: MenuItem[] ): void {
105+
this.menuVegetableItems = newMenuItems;
106+
},
83107
},
84108
},
85109
methods: {
86110
onScroll( firstIndex: number, lastIndex: number ): void {
87111
this.visibleItems = { firstIndex, lastIndex };
112+
if ( lastIndex === this.menuItems.length - 1 ) {
113+
this.menuItems = [ ...vegetableItems, ...itemsToAddOnScroll ];
114+
}
88115
},
89116
},
90117
template: `
91118
<div>
92119
<div style="margin-bottom: 20px">
120+
<p>Try pressing <kbd>a</kbd> to see several search results.
121+
Some additional results will load when you scroll.</p>
93122
<Lookup
94123
:search-input.sync="search"
95124
label="Label"

0 commit comments

Comments
 (0)