Skip to content

Commit

Permalink
Trim text in TextHighlight
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Feb 20, 2020
1 parent ff5016b commit d895cab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ function LinkControl( {
isURL={ directLinkEntryTypes.includes(
suggestion.type.toLowerCase()
) }
searchTerm={ inputValue.trim() }
searchTerm={ inputValue }
/>
);
} ) }
Expand Down
9 changes: 7 additions & 2 deletions packages/components/src/text-highlight/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import { escapeRegExp } from 'lodash';
import { __experimentalCreateInterpolateElement } from '@wordpress/element';

const TextHighlight = ( { text = '', highlight = '' } ) => {
if ( ! highlight.trim() ) {
const trimmedHighlightText = highlight.trim();

if ( ! trimmedHighlightText ) {
return text;
}

const regex = new RegExp( `(${ escapeRegExp( highlight ) })`, 'gi' );
const regex = new RegExp(
`(${ escapeRegExp( trimmedHighlightText ) })`,
'gi'
);

return __experimentalCreateInterpolateElement(
text.replace( regex, '<mark>$&</mark>' ),
Expand Down

0 comments on commit d895cab

Please sign in to comment.