* Improve PartialHighlighter error handling
(cherry picked from commit 05bb451a1d)
Co-authored-by: Connor Lindsey <cblindsey3@gmail.com>
This commit is contained in:
co-authored by
Connor Lindsey
parent
2e86425ed9
commit
d38782bc94
@@ -45,4 +45,11 @@ describe('PartialHighlighter component', () => {
|
||||
assertPart(main.childAt(1), false, ' ipsum dolor sit ');
|
||||
assertPart(main.childAt(2), true, 'amet');
|
||||
});
|
||||
|
||||
it('returns null if highlightParts is empty', () => {
|
||||
const component = mount(
|
||||
<PartialHighlighter text="Lorem ipsum dolor sit amet" highlightClassName="highlight" highlightParts={[]} />
|
||||
);
|
||||
expect(component.html()).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ function getStartIndices(parts: HighlightPart[], length: number): number[] {
|
||||
export const PartialHighlighter: React.FC<Props> = (props: Props) => {
|
||||
let { highlightParts, text, highlightClassName } = props;
|
||||
|
||||
if (!highlightParts) {
|
||||
if (!highlightParts?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user