Prevent no items message from displaying whilst items are being fetched

This commit is contained in:
Tom Southall
2022-03-15 15:41:32 +00:00
parent aad534f187
commit cbe957195d
5 changed files with 7 additions and 6 deletions

View File

@@ -1,5 +1,8 @@
# Changelog # Changelog
### 1.1.2 (15 Mar 2022)
- Prevent no items message from displaying whilst items are being fetched
### 1.1.2 (15 Mar 2022) ### 1.1.2 (15 Mar 2022)
- Add note to README regarding onSelect being called when an item is no longer selected - Add note to README regarding onSelect being called when an item is no longer selected

View File

@@ -86,7 +86,6 @@ const App = () => {
placeholder={placeholder} placeholder={placeholder}
plugins={[[recentSearchesPlugin, {ratio: 2, name: 'Recent', limit: maxItems}]]} plugins={[[recentSearchesPlugin, {ratio: 2, name: 'Recent', limit: maxItems}]]}
styles={autocompleteStyles} styles={autocompleteStyles}
text="bar"
typeahead={true} typeahead={true}
Cancel={CancelButton} Cancel={CancelButton}
Clear={ClearButton} Clear={ClearButton}

View File

@@ -1,6 +1,6 @@
{ {
"name": "turnstone", "name": "turnstone",
"version": "1.1.2", "version": "1.1.3",
"description": "React customisable autocomplete component with typeahead and grouped results from multiple APIs.", "description": "React customisable autocomplete component with typeahead and grouped results from multiple APIs.",
"author": "Tom Southall", "author": "Tom Southall",
"keywords": [ "keywords": [

View File

@@ -14,7 +14,6 @@ const reducer = (state, action) => {
switch (action.type) { switch (action.type) {
case types.SET_QUERY: case types.SET_QUERY:
newState = { newState = {
canShowListbox: !!action.query.length,
itemsError: false, itemsError: false,
query: action.query, query: action.query,
selected: undef selected: undef
@@ -37,7 +36,8 @@ const reducer = (state, action) => {
? highlightedItem(0, action.items) ? highlightedItem(0, action.items)
: undef : undef
} }
if(action.items.length) newState.canShowListbox = true
if(state.query.length || action.items.length) newState.canShowListbox = true
return newState return newState
case types.CLEAR: case types.CLEAR:

View File

@@ -7,7 +7,6 @@ import { defaultListbox } from '../../../examples/_shared/defaultListbox'
describe('SET_QUERY action', () => { describe('SET_QUERY action', () => {
test('produces expected new state', () => { test('produces expected new state', () => {
const state = { const state = {
canShowListbox: false,
itemsError: true, itemsError: true,
query: 'foo', query: 'foo',
selected: {index: 0, text: 'Foobar'}, selected: {index: 0, text: 'Foobar'},
@@ -19,7 +18,6 @@ describe('SET_QUERY action', () => {
const action = actions.setQuery('bar') const action = actions.setQuery('bar')
expect(reducer(state, action)).toEqual({ expect(reducer(state, action)).toEqual({
canShowListbox: true,
itemsError: false, itemsError: false,
query: 'bar', query: 'bar',
selected: undef, selected: undef,
@@ -132,6 +130,7 @@ describe('SET_ITEMS action', () => {
query: 'foo', query: 'foo',
items, items,
itemsError: false, itemsError: false,
canShowListbox: true,
highlighted: undef highlighted: undef
}) })
}) })