diff --git a/src/App.jsx b/src/App.jsx index f0b5bd6..e1060c0 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -18,6 +18,7 @@ const App = () => { noItemsMessage={'No matching fruit found'} placeholder={'Type something fruity'} styles={styles} + minQueryLength={1} /> ) } diff --git a/src/data.js b/src/data.js index 69ef8c1..7601ecb 100644 --- a/src/data.js +++ b/src/data.js @@ -7,10 +7,11 @@ const fruits = [ "Blackberry", "Blackcurrant", "Blueberry", - "Currant", + "Cantaloupe", "Cherry", "Cherimoya", "Clementine", + "Currant", "Date", "Damson", "Durian", @@ -21,6 +22,7 @@ const fruits = [ "Grape", "Grapefruit", "Guava", + "Honeydew melon", "Huckleberry", "Jackfruit", "Jambul", @@ -33,23 +35,19 @@ const fruits = [ "Mango", "Mangostine", "Melon", - "Cantaloupe", - "Honeydew melon", - "Watermelon", "Rock melon", "Nectarine", "Orange", "Peach", "Pear", - "Williams pear or Bartlett pear", - "Pitaya", "Physalis", - "Plum/prune (dried plum)", "Pineapple", + "Pitaya", + "Plum", "Pomegranate", + "Prune", "Raisin", "Raspberry", - "Western raspberry (blackcap)", "Rambutan", "Redcurrant", "Salal berry", @@ -60,6 +58,8 @@ const fruits = [ "Tomato", "Ugli fruit", "Watermelon", + "Western raspberry (blackcap)", + "Williams pear or Bartlett pear", "Ziziphus mauritiana" ] diff --git a/src/lib/components/container.jsx b/src/lib/components/container.jsx index f12701e..1ff56f5 100644 --- a/src/lib/components/container.jsx +++ b/src/lib/components/container.jsx @@ -3,12 +3,16 @@ import setify from 'setify' // Sets input value without changing cursor position import { StateContext } from '../context/state' import Items from './items' import { useDebounce } from 'use-debounce' -import { useItemsState, useAutoFocus, useQueryChange } from './hooks/containerEffects' import useData from './hooks/useData' import undef from '../utils/undef' import isUndefined from '../utils/isUndefined' import startsWithCaseInsensitive from '../utils/startsWithCaseInsensitive' import defaultStyles from './styles/input.styles.js' +import { + useItemsState, + useAutoFocus, + useQueryChange, +} from './hooks/containerEffects' import { setQuery, setHighlighted, @@ -32,7 +36,6 @@ export default function Container(props) { itemGroupsAreImmutable, maxItems, minQueryLength, - loadingMessage, noItemsMessage, onChange, onSelect, @@ -61,7 +64,6 @@ export default function Container(props) { // Component state const [debouncedQuery] = useDebounce(state.query, debounceWait) const [hasFocus, setHasFocus] = useState(false) - const [isLoading, setIsLoading] = useState(false) // DOM references const queryInput = useRef(null) @@ -96,12 +98,6 @@ export default function Container(props) { // typeahead value and the query value and fire onChnage useQueryChange(state.query, queryInput, typeaheadInput, onChange) - // Figure out whether we are able to display a loading state - useEffect(() => { - if (state.items && state.items.length) setIsLoading(false) - else if (state.query.length <= minQueryLength) setIsLoading(true) - }, [state.items, state.query, minQueryLength, setIsLoading]) - // When the highlighted item changes, make sure the typeahead matches and format // the query text to match the case of the typeahead text useEffect(() => { @@ -256,9 +252,7 @@ export default function Container(props) { {isDropdown() && ( )} diff --git a/src/lib/components/items.jsx b/src/lib/components/items.jsx index 6ce39aa..881cc75 100644 --- a/src/lib/components/items.jsx +++ b/src/lib/components/items.jsx @@ -3,10 +3,9 @@ import { StateContext } from '../context/state' import defaultStyles from './styles/items.styles.js' import ItemFirst from './itemFirst' import Item from './item' -import isUndefined from '../utils/isUndefined' export default function Items(props) { - const { isLoading, items, loadingMessage, noItemsMessage } = props + const { items, noItemsMessage } = props const { state } = useContext(StateContext) const { customStyles } = state @@ -29,22 +28,10 @@ export default function Items(props) { ) } - const showLoadingMessage = useMemo(() => { - return isLoading && !isUndefined(loadingMessage) - }, [isLoading, loadingMessage]) - const noItemsMsg = () => { - const msg = showLoadingMessage - ? loadingMessage - : noItemsMessage - - const msgClassName = showLoadingMessage - ? customStyles.loading - : customStyles.noItems - return (
-
{msg}
+
{noItemsMessage}
) } @@ -52,9 +39,11 @@ export default function Items(props) { const dropdown = () => { if (items && items.length) { return itemElements() - } else if ((noItemsMessage && !isLoading) || showLoadingMessage) { + } + else if (noItemsMessage && state.query) { return noItemsMsg() - } else { + } + else { return } } diff --git a/src/lib/context/state.jsx b/src/lib/context/state.jsx index eeb2b3c..3c8bf4a 100644 --- a/src/lib/context/state.jsx +++ b/src/lib/context/state.jsx @@ -13,7 +13,6 @@ const StateContextProvider = (props) => { items, highlighted: undef, selected: undef, - isLoading: false, customStyles: styles, splitChar, props: propsMinusChildren diff --git a/src/lib/index.jsx b/src/lib/index.jsx index 1fa0e60..b63d0f1 100644 --- a/src/lib/index.jsx +++ b/src/lib/index.jsx @@ -72,7 +72,6 @@ Turnstone.propTypes = { ) }, itemGroupsAreImmutable: PropTypes.bool, - loadingMessage: PropTypes.string, minQueryLength: (props) => { PropTypes.checkPropTypes( {minQueryLength: PropTypes.number}, @@ -80,7 +79,9 @@ Turnstone.propTypes = { 'prop', 'Turnstone' ) if(props.minQueryLength < propDefaults.minQueryLength) - return new Error(`Prop "minQueryLength" must be a number greater than ${propDefaults.minQueryLength - 1}`) + return new Error( + `Prop "minQueryLength" must be a number greater than ${propDefaults.minQueryLength - 1}` + ) }, noItemsMessage: PropTypes.string, onChange: PropTypes.func,