Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: No default suggestion selected (#24479)
* QueryField: No default suggestion selected It's been a long-standing issue that careless typing lead to unwanted tab completion insertions. With this change the completion item list no longer selects the first item by default. The user has to actively click ArrowDown to select the first one. * Added type export * Remove width limit of typeahead list
- Loading branch information
Showing
3 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/grafana-ui/src/components/Typeahead/Typeahead.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { Typeahead, State } from './Typeahead'; | ||
import { TypeaheadItem } from './TypeaheadItem'; | ||
import { CompletionItemKind } from '../../types'; | ||
|
||
describe('Typeahead', () => { | ||
const completionItemGroups = [{ label: 'my group', items: [{ label: 'first item' }] }]; | ||
describe('when closed', () => { | ||
it('renders nothing when no items given', () => { | ||
const component = mount(<Typeahead origin="test" groupedItems={[]} />); | ||
expect(component.find('.typeahead')).toHaveLength(0); | ||
}); | ||
it('renders nothing when items given', () => { | ||
const component = mount(<Typeahead origin="test" groupedItems={completionItemGroups} />); | ||
expect(component.find('.typeahead')).toHaveLength(0); | ||
}); | ||
}); | ||
describe('when open', () => { | ||
it('renders given items and nothing is selected', () => { | ||
const component = mount(<Typeahead origin="test" groupedItems={completionItemGroups} isOpen />); | ||
expect(component.find('.typeahead')).toHaveLength(1); | ||
const items = component.find(TypeaheadItem); | ||
expect(items).toHaveLength(2); | ||
expect(items.get(0).props.item.kind).toEqual(CompletionItemKind.GroupTitle); | ||
expect(items.get(0).props.isSelected).toBeFalsy(); | ||
expect(items.get(1).props.item.label).toEqual('first item'); | ||
expect(items.get(1).props.isSelected).toBeFalsy(); | ||
}); | ||
}); | ||
it('selected the first non-group item on moving to first item', () => { | ||
const component = mount(<Typeahead origin="test" groupedItems={completionItemGroups} isOpen />); | ||
expect(component.find('.typeahead')).toHaveLength(1); | ||
let items = component.find(TypeaheadItem); | ||
|
||
expect(items).toHaveLength(2); | ||
expect((component.state() as State).typeaheadIndex).toBe(null); | ||
(component.instance() as Typeahead).moveMenuIndex(1); | ||
expect((component.state() as State).typeaheadIndex).toBe(1); | ||
component.setProps({}); | ||
items = component.find(TypeaheadItem); | ||
expect(items.get(0).props.isSelected).toBeFalsy(); | ||
expect(items.get(1).props.isSelected).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters