Skip to content

Commit

Permalink
Check if children are wrapped only when there is on child
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorGa committed Oct 20, 2023
1 parent 2dca619 commit 9dff8a4
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ export const SplitTextWrapper: SplitTextWrapperComponent = ensuredForwardRef(
return;
}

/**
* Detecting the if firstChild is an element only if there is only one child
*/
const content =
element.firstChild?.nodeType === Node.ELEMENT_NODE
? element.querySelector((element.firstChild as HTMLElement).tagName.toLowerCase())
element.children.length === 1 && element.firstChild?.nodeType === Node.ELEMENT_NODE
? (element.firstChild as HTMLElement)
: element;

ref.current = new SplitText(content, variables);
};

Expand Down

0 comments on commit 9dff8a4

Please sign in to comment.