diff --git a/packages/grafana-ui/src/components/Typeahead/Typeahead.test.tsx b/packages/grafana-ui/src/components/Typeahead/Typeahead.test.tsx index 34cac0ba896..ffe7380e941 100644 --- a/packages/grafana-ui/src/components/Typeahead/Typeahead.test.tsx +++ b/packages/grafana-ui/src/components/Typeahead/Typeahead.test.tsx @@ -3,7 +3,7 @@ import { mount } from 'enzyme'; import { Typeahead, State } from './Typeahead'; import { TypeaheadItem } from './TypeaheadItem'; -import { CompletionItemKind } from '../../types'; +import { CompletionItemGroup, CompletionItemKind } from '../../types'; describe('Typeahead', () => { const completionItemGroups = [{ label: 'my group', items: [{ label: 'first item' }] }]; @@ -43,4 +43,14 @@ describe('Typeahead', () => { expect(items.get(0).props.isSelected).toBeFalsy(); expect(items.get(1).props.isSelected).toBeTruthy(); }); + it('can be rendered properly even if the size of items is large', () => { + const completionItemGroups: CompletionItemGroup[] = [{ label: 'my group', items: [] }]; + const itemsSize = 1000000; + for (let i = 0; i < itemsSize; i++) { + completionItemGroups[0].items.push({ label: 'item' + i }); + } + + const component = mount(); + expect(component.find('.typeahead')).toHaveLength(1); + }); }); diff --git a/packages/grafana-ui/src/utils/typeahead.ts b/packages/grafana-ui/src/utils/typeahead.ts index 6842a72296d..980cbe63a61 100644 --- a/packages/grafana-ui/src/utils/typeahead.ts +++ b/packages/grafana-ui/src/utils/typeahead.ts @@ -4,12 +4,14 @@ import { GrafanaTheme } from '@grafana/data'; export const flattenGroupItems = (groupedItems: CompletionItemGroup[]): CompletionItem[] => { return groupedItems.reduce((all: CompletionItem[], { items, label }) => { - const titleItem: CompletionItem = { + all.push({ label, kind: CompletionItemKind.GroupTitle, - }; - all.push(titleItem, ...items); - return all; + }); + return items.reduce((all, item) => { + all.push(item); + return all; + }, all); }, []); };