how to highlight or bold the searched text in the options? #5515
Unanswered
omerbarda130
asked this question in
Q&A
Replies: 3 comments 6 replies
-
Hi @omerbarda130
Hope it helps. |
Beta Was this translation helpful? Give feedback.
4 replies
-
Here's what I am using in 2024. works great |
Beta Was this translation helpful? Give feedback.
1 reply
-
This approach handles case insensitive matching and works for input strings that include characters that would blow up regular expressions. const makeBold = (item: string, keyword: string) => {
const lowerCasedInputValue = keyword.toLowerCase()
const hitIndex = item.toLocaleLowerCase().indexOf(lowerCasedInputValue)
if (hitIndex === -1) return item
const before = item.slice(0, hitIndex)
const match = item.slice(hitIndex, hitIndex + keyword.length)
const after = item.slice(hitIndex + keyword.length)
return (
<span>
{before}
<b>{match}</b>
{after}
</span>
)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
i want when the dropdown menu is open the be able to highlight the text i searched in the options
if i search the text :"ba" the options needs to be Bangladeshi Batswana etc
Beta Was this translation helpful? Give feedback.
All reactions