Fix dropdown and multiselect breaking when searched with special characters

This commit is contained in:
Nakul Nagargade 2025-04-11 15:23:28 +05:30 committed by devanshu052000
parent 3bd1f78ea3
commit de7fd59113

View file

@ -52,7 +52,14 @@ export const getInputBackgroundColor = ({ fieldBackgroundColor, darkMode, isLoad
};
export const highlightText = (text = '', highlight) => {
const parts = text?.split(new RegExp(`(${highlight})`, 'gi'));
// Escape special regex characters in the highlight string
const escapeRegExp = (string) => {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
};
const safeHighlight = highlight ? escapeRegExp(highlight) : '';
const parts = text?.split(new RegExp(`(${safeHighlight})`, 'gi'));
return (
<span>
{parts.map((part, index) =>