Skip to content

Commit 8905d6c

Browse files
authored
Merge pull request #49 from pixelos-cc/master
Fix for keyboard navigation in filtered lists
2 parents ffd2e65 + a6d45d2 commit 8905d6c

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/Typeahead.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ export default class Typeahead extends PureComponent<Props, State> {
571571
} else {
572572
options.forEach((option, index) => rows.push({
573573
option,
574-
index
574+
index: this._getAbsoluteIndex(option)
575575
}));
576576
}
577577
return rows;
@@ -656,6 +656,7 @@ export default class Typeahead extends PureComponent<Props, State> {
656656
noRowsRenderer={this._noRowsRenderer}
657657
rowHeight={calculateRowHeight}
658658
rowRenderer={renderRow}
659+
tabIndex={null}
659660
scrollToAlignment="start"
660661
{...scrollToIndexProp}
661662
/>

src/Typeahead.spec.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,33 @@ describe('Typeahead should', () => {
250250
expect(Boolean(value1Option.prop('data-highlighted'))).toEqual(true);
251251
});
252252

253+
it('highlight second option in a filtered list when no value is set and arrow down key is pressed twice', function () {
254+
const wrapper = mount(<Typeahead fieldName="fieldName" options={options}/>);
255+
wrapper.find('input').simulate('focus');
256+
simulateKeys(wrapper.find('input'), 'spe');
257+
wrapper.find('input').simulate('keyDown', {keyCode: KEY_DOWN});
258+
wrapper.find('input').simulate('keyDown', {keyCode: KEY_DOWN});
259+
const value1Option = wrapper.find('.typeahead__option[data-value="value4"]');
260+
expect(Boolean(value1Option.prop('data-highlighted'))).toEqual(true);
261+
});
262+
263+
it('highlight the right option in a filtered list when no value is set and arrow down key is pressed twice', function () {
264+
const optionsForFilter = [
265+
{label: 'nomatch', value: 'value1'},
266+
{label: 'nomatch', value: 'value2'},
267+
{label: 'match haus', value: 'value3'},
268+
{label: 'nomatch', value: 'value4'},
269+
{label: 'match haus 2', value: 'value5'}
270+
];
271+
const wrapper = mount(<Typeahead fieldName="fieldName" options={optionsForFilter}/>);
272+
wrapper.find('input').simulate('focus');
273+
simulateKeys(wrapper.find('input'), 'haus');
274+
wrapper.find('input').simulate('keyDown', {keyCode: KEY_DOWN});
275+
wrapper.find('input').simulate('keyDown', {keyCode: KEY_DOWN});
276+
const value1Option = wrapper.find('.typeahead__option[data-value="value5"]');
277+
expect(Boolean(value1Option.prop('data-highlighted'))).toEqual(true);
278+
});
279+
253280
it('highlight first option when no value is set and arrow up key is pressed', function () {
254281
const wrapper = mount(<Typeahead fieldName="fieldName" options={options}/>);
255282
wrapper.find('input').simulate('focus');

0 commit comments

Comments
 (0)