Skip to content

Allow highlighting multiple strings with TextHighlight component#42289

Closed
danieliser wants to merge 4 commits into
WordPress:trunkfrom
danieliser:components/multiple-highlight-strings
Closed

Allow highlighting multiple strings with TextHighlight component#42289
danieliser wants to merge 4 commits into
WordPress:trunkfrom
danieliser:components/multiple-highlight-strings

Conversation

@danieliser

@danieliser danieliser commented Jul 10, 2022

Copy link
Copy Markdown
Contributor

What?

Modifies TextHighlight to accept string | string[] for highlight prop.

Why?

Was attempting to highlight multiple strings and found this impossible with the current version.

  • Nesting didn't work as it expects the text to be a string, and thus can't handle nesting one highlight inside another.
  • Passing a joined string using | for regex match is stripped out during escaping.

How?

  1. Convert single highlight string to [ highlight ] so its always an array for mapping.
  2. Mapped highlight strings through trim, filtered empty results, then filtered again through escapeRegex
  3. Modified the regex match and empty highlight text checks to work with an array of values joined using |.

Screenshots or screencast

image

<TextHighlight
    text={ 'User Has Role(s)' }
    highlight={ [ 'user', 'role' ] }
/>

@danieliser danieliser requested a review from ajitbohra as a code owner July 10, 2022 01:13
@skorasaurus skorasaurus added the [Package] Components /packages/components label Aug 25, 2022
@danieliser danieliser closed this by deleting the head repository Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants