Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ yarn ios
| `closeOnSubmit` | whether to close dropdown on submit | bool | false |
| `clearOnFocus` | whether to clear typed text on focus | bool | true |
| `ignoreAccents` | ignore diacritics | bool | true |
| `trimSearchText` | trim the searched text | bool | true |
| `debounce` | wait **ms** before call `onChangeText` | number | 0 |
| `suggestionsListMaxHeight` | max height of dropdown | number | 200 |
| `direction` | "up" or "down" | string | down + auto calculate |
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface AutocompleteDropdownProps {
closeOnSubmit?: boolean
clearOnFocus?: boolean
ignoreAccents?: boolean
trimSearchText?: boolean
matchFrom?: 'any' | 'start'
debounce?: number
direction?: 'down' | 'up'
Expand Down
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const AutocompleteDropdown = memo(
const [dataSet, setDataSet] = useState(props.dataSet)
const clearOnFocus = props.clearOnFocus === false ? false : true
const ignoreAccents = props.ignoreAccents === false ? false : true
const trimSearchText = props.trimSearchText === false ? false : true
const matchFromStart = props.matchFrom === 'start' ? true : false
const inputHeight = props.inputHeight ?? moderateScale(40, 0.2)
const suggestionsListMaxHeight = props.suggestionsListMaxHeight ?? moderateScale(200, 0.2)
Expand Down Expand Up @@ -191,7 +192,15 @@ export const AutocompleteDropdown = memo(
return
}

const findWhat = ignoreAccents ? diacriticless(searchText.toLowerCase()) : searchText.toLowerCase()
let findWhat = searchText.toLowerCase()

if (ignoreAccents) {
findWhat = diacriticless(findWhat)
}

if (trimSearchText) {
findWhat = findWhat.trim()
}

const newSet = props.dataSet.filter(item => {
const findWhere = ignoreAccents ? diacriticless(item.title.toLowerCase()) : item.title.toLowerCase()
Expand Down