bright-components 10.2.5 → 10.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -171,7 +171,7 @@ class Typeahead extends _react.default.Component {
|
|
171
171
|
let nextIndex = highlightIndex;
|
172
172
|
const isActionKey = ['ArrowDown', 'ArrowUp', 'Enter', 'Escape', 'Tab'].includes(e.key);
|
173
173
|
|
174
|
-
if (!isActionKey) {
|
174
|
+
if (!isActionKey || !this.options[highlightIndex]) {
|
175
175
|
return;
|
176
176
|
}
|
177
177
|
|
package/package.json
CHANGED
@@ -228,6 +228,13 @@ describe('<Typeahead />', () => {
|
|
228
228
|
[firstOption, secondOption] = wrapper.getAllByRole('listitem');
|
229
229
|
expect(firstOption).not.toHaveStyleRule('background', '#D0EBFD');
|
230
230
|
expect(secondOption).toHaveStyleRule('background', '#D0EBFD');
|
231
|
+
|
232
|
+
fireEvent.keyDown(input, { key: 'ArrowUp' });
|
233
|
+
fireEvent.keyDown(input, { key: 'ArrowUp' });
|
234
|
+
fireEvent.keyDown(input, { key: 'ArrowUp' });
|
235
|
+
|
236
|
+
expect(firstOption).toHaveStyleRule('background', '#D0EBFD');
|
237
|
+
expect(secondOption).not.toHaveStyleRule('background', '#D0EBFD');
|
231
238
|
});
|
232
239
|
|
233
240
|
it('should highlight a new option on the up arrow key', () => {
|
@@ -284,5 +291,16 @@ describe('<Typeahead />', () => {
|
|
284
291
|
|
285
292
|
expect(scrollIntoView).not.toHaveBeenCalled();
|
286
293
|
});
|
294
|
+
|
295
|
+
it('should handle live updates to the list changing the length of the list', () => {
|
296
|
+
const input = wrapper.getByPlaceholderText('Search or select');
|
297
|
+
|
298
|
+
fireEvent.focus(input);
|
299
|
+
|
300
|
+
wrapper.rerender(<Typeahead {...props} options={[]} />);
|
301
|
+
fireEvent.keyDown(input, { key: 'Enter' });
|
302
|
+
|
303
|
+
expect(setSelected).toHaveBeenCalledTimes(0);
|
304
|
+
});
|
287
305
|
});
|
288
306
|
});
|