Skip to content

Commit 63a287d

Browse files
authored
feat: add a prop to trim the seached text by default (#103)
1 parent 5f16c94 commit 63a287d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ yarn ios
265265
| `closeOnSubmit` | whether to close dropdown on submit | bool | false |
266266
| `clearOnFocus` | whether to clear typed text on focus | bool | true |
267267
| `ignoreAccents` | ignore diacritics | bool | true |
268+
| `trimSearchText` | trim the searched text | bool | true |
268269
| `debounce` | wait **ms** before call `onChangeText` | number | 0 |
269270
| `suggestionsListMaxHeight` | max height of dropdown | number | 200 |
270271
| `direction` | "up" or "down" | string | down + auto calculate |

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface AutocompleteDropdownProps {
3636
closeOnSubmit?: boolean
3737
clearOnFocus?: boolean
3838
ignoreAccents?: boolean
39+
trimSearchText?: boolean
3940
matchFrom?: 'any' | 'start'
4041
debounce?: number
4142
direction?: 'down' | 'up'

src/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const AutocompleteDropdown = memo(
3535
const [dataSet, setDataSet] = useState(props.dataSet)
3636
const clearOnFocus = props.clearOnFocus === false ? false : true
3737
const ignoreAccents = props.ignoreAccents === false ? false : true
38+
const trimSearchText = props.trimSearchText === false ? false : true
3839
const matchFromStart = props.matchFrom === 'start' ? true : false
3940
const inputHeight = props.inputHeight ?? moderateScale(40, 0.2)
4041
const suggestionsListMaxHeight = props.suggestionsListMaxHeight ?? moderateScale(200, 0.2)
@@ -191,7 +192,15 @@ export const AutocompleteDropdown = memo(
191192
return
192193
}
193194

194-
const findWhat = ignoreAccents ? diacriticless(searchText.toLowerCase()) : searchText.toLowerCase()
195+
let findWhat = searchText.toLowerCase()
196+
197+
if (ignoreAccents) {
198+
findWhat = diacriticless(findWhat)
199+
}
200+
201+
if (trimSearchText) {
202+
findWhat = findWhat.trim()
203+
}
195204

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

0 commit comments

Comments
 (0)