From 9dff8a476d86e30311015952ef8af7fc08ace9e8 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 20 Oct 2023 14:09:45 +0200 Subject: [PATCH] Check if children are wrapped only when there is on child --- .../src/SplitTextWrapper/SplitTextWrapper.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-animation/src/SplitTextWrapper/SplitTextWrapper.tsx b/packages/react-animation/src/SplitTextWrapper/SplitTextWrapper.tsx index df05abf..654ffd1 100644 --- a/packages/react-animation/src/SplitTextWrapper/SplitTextWrapper.tsx +++ b/packages/react-animation/src/SplitTextWrapper/SplitTextWrapper.tsx @@ -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); };