Skip to content

Commit 34d2ab1

Browse files
authored
Merge pull request hossein-zare#625 from marcel-fly/dev-5.x
Add ability to search with regional accents
2 parents d70a550 + 31b49da commit 34d2ab1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ declare module 'react-native-dropdown-picker' {
174174
searchContainerStyle?: StyleProp<ViewStyle>;
175175
searchTextInputStyle?: StyleProp<TextStyle>;
176176
searchPlaceholderTextColor?: string;
177+
searchWithRegionalAccents?: boolean;
177178
dropDownContainerStyle?: StyleProp<ViewStyle>;
178179
modalContentContainerStyle?: StyleProp<ViewStyle>;
179180
modalAnimationType?: 'none' | 'slide' | 'fade';

src/components/Picker.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function Picker({
9999
listMode = LIST_MODE.DEFAULT,
100100
categorySelectable = true,
101101
searchable = false,
102+
searchWithRegionalAccents = false,
102103
searchPlaceholder = null,
103104
modalTitle,
104105
schema = {},
@@ -455,8 +456,14 @@ function Picker({
455456
return sortedItems;
456457

457458
const values = [];
459+
const normalizeText = (text) => text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
460+
458461
let results = sortedItems.filter(item => {
459-
if (item[_schema.label].toLowerCase().includes(searchText.toLowerCase())) {
462+
const label = item[_schema.label].toLowerCase();
463+
if (
464+
label.includes(searchText.toLowerCase())
465+
|| searchWithRegionalAccents && normalizeText(label).includes(searchText.toLowerCase())
466+
) {
460467
values.push(item[_schema.value]);
461468
return true;
462469
}

0 commit comments

Comments
 (0)