Skip to content

Commit

Permalink
fix: search regex issue
Browse files Browse the repository at this point in the history
  • Loading branch information
azeezat committed Nov 30, 2023
1 parent 7e49a9c commit cf04a86
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -620,4 +620,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 5c80fa76d05da1d4e17685423f650ebe38a55415

COCOAPODS: 1.12.1
COCOAPODS: 1.13.0
1 change: 1 addition & 0 deletions src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const Input = ({
onBlur={() => setFocus(false)}
value={value}
onChangeText={onChangeText}
returnKeyType="search"
{...rest}
/>
</View>
Expand Down
9 changes: 5 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
TSectionList,
TSectionListItem,
} from './types/index.types';
import { extractPropertyFromArray } from './utils';
import { escapeRegExp, extractPropertyFromArray } from './utils';

export const DropdownSelect: React.FC<DropdownProps> = ({
placeholder,
Expand Down Expand Up @@ -226,7 +226,7 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
const onSearch = (value: string) => {
setSearchValue(value);

let searchText = value.toString().toLocaleLowerCase().trim();
let searchText = escapeRegExp(value).toString().toLocaleLowerCase().trim();

const regexFilter = new RegExp(searchText, 'i');

Expand Down Expand Up @@ -276,8 +276,9 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
* Modal
*==========================================*/
const handleToggleModal = () => {
if (disabled){ // protecting any toggleModal invocation when Dropdown is disabled by not activating state
return;
if (disabled) {
// protecting any toggleModal invocation when Dropdown is disabled by not activating state
return;
}
setOpen(!open);
setSearchValue('');
Expand Down
4 changes: 4 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export const extractPropertyFromArray = (arr: any, property: string) => {

return extractedValue;
};

export const escapeRegExp = (text: string) => {
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
};

0 comments on commit cf04a86

Please sign in to comment.