Skip to content

Commit

Permalink
Merge pull request #114 from osstotalsoft/autocomplete-state-aware-no…
Browse files Browse the repository at this point in the history
…OptionsText

Made noOptionsText state aware
  • Loading branch information
alexandra-c authored Jun 25, 2024
2 parents c0b2eeb + 7c724be commit ae03e62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/components/inputs/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ const Autocomplete: React.FC<AutocompleteProps<any, any, any, any>> = ({
setOptions(receivedOptions || [])
}, [receivedOptions])

const localNoOptionsText = useMemo(() => {
if (!noOptionsText || typeof noOptionsText !== 'function') return noOptionsText as React.ReactNode
return noOptionsText(localInput, localLoading)
}, [noOptionsText, localInput, localLoading])

const listBoxProps = useMemo(
() =>
isPaginated
Expand All @@ -331,7 +336,7 @@ const Autocomplete: React.FC<AutocompleteProps<any, any, any, any>> = ({

return (
<MuiAutocomplete
noOptionsText={<NoOptionsText color={typographyContentColor}>{noOptionsText}</NoOptionsText>}
noOptionsText={<NoOptionsText color={typographyContentColor}>{localNoOptionsText}</NoOptionsText>}
typographyContentColor={typographyContentColor}
forcePopupIcon
label={label}
Expand Down
3 changes: 2 additions & 1 deletion src/components/inputs/Autocomplete/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface AutocompleteProps<
| 'multiple'
| 'disableClearable'
| 'renderTags'
| 'noOptionsText'
> {
/**
* Array of options.
Expand Down Expand Up @@ -139,7 +140,7 @@ export interface AutocompleteProps<
* Text to display when there are no options.
* For localization purposes, you can use the provided translations.
*/
noOptionsText?: React.ReactNode
noOptionsText?: React.ReactNode | ((inputValue: string, loadingOptions: boolean) => React.ReactNode)
/**
* The color of selected input.
*/
Expand Down

0 comments on commit ae03e62

Please sign in to comment.