mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 00:48:25 +00:00
Fix dropdown and multiselect breaking when searched with special characters
This commit is contained in:
parent
3bd1f78ea3
commit
de7fd59113
1 changed files with 8 additions and 1 deletions
|
|
@ -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) =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue