diff --git a/packages/react-ui/components/Token/Token.tsx b/packages/react-ui/components/Token/Token.tsx index d9a7f7a4d7..b0eed9b602 100644 --- a/packages/react-ui/components/Token/Token.tsx +++ b/packages/react-ui/components/Token/Token.tsx @@ -2,7 +2,7 @@ import React, { AriaAttributes } from 'react'; import { locale } from '../../lib/locale/decorators'; import { CrossIcon } from '../../internal/icons/CrossIcon'; -import { emptyHandler, getChildrenText } from '../../lib/utils'; +import { emptyHandler } from '../../lib/utils'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; @@ -10,6 +10,7 @@ import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { isTheme2022 } from '../../lib/theming/ThemeHelpers'; import { CloseButtonIcon } from '../../internal/CloseButtonIcon/CloseButtonIcon'; +import { reactGetTextContent } from '../../lib/reactGetTextContent'; import { styles, colorStyles, globalClasses } from './Token.styles'; import { TokenLocale, TokenLocaleHelper } from './locale'; @@ -98,7 +99,7 @@ export class Token extends React.Component { const theme = this.theme; const validation = getValidation(error, warning); - const removeButtonAriaLabel = this.locale.removeButtonAriaLabel + ' ' + getChildrenText(children); + const removeButtonAriaLabel = this.locale.removeButtonAriaLabel + ' ' + reactGetTextContent(children); const icon = isTheme2022(theme) ? ( 123, }, + + { label: '', renderNode: () => false }, ]; describe('reactGetTextContent', () => { diff --git a/packages/react-ui/lib/utils.ts b/packages/react-ui/lib/utils.ts index 5d2eb21635..20e0cc7f39 100644 --- a/packages/react-ui/lib/utils.ts +++ b/packages/react-ui/lib/utils.ts @@ -223,26 +223,3 @@ export const isInputLike = export const isKonturIcon = (icon: React.ReactElement) => { return Object.prototype.hasOwnProperty.call(icon?.type, '__KONTUR_ICON__'); }; - -/** - * Allows to get text of all nested children as a string - * - * @param children React's children - * @returns Nested child text or an empty string - */ -export function getChildrenText(children: React.ReactNode): string { - if (typeof children === 'string' || typeof children === 'number') { - return children.toString(); - } - - if (Array.isArray(children)) { - return children.map((entry) => getChildrenText(entry)).join(''); - } - - const nextChild = (children as React.ReactElement)?.props.children; - if (!nextChild) { - return ''; - } - - return getChildrenText(nextChild); -}