Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Token): correct render with conditional children #3404

Merged
merged 10 commits into from
Apr 16, 2024
4 changes: 4 additions & 0 deletions packages/react-ui/components/Token/__tests__/Token-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,9 @@ describe('Token', () => {

expect(screen.getByRole('button')).toHaveAttribute('aria-label', TokenLocalesRu.removeButtonAriaLabel + ' ');
});

it('doesn`t throw on conditional render', () => {
expect(() => render(<Token>{false && 'Deleted'}</Token>)).not.toThrow();
});
zhzz marked this conversation as resolved.
Show resolved Hide resolved
});
});
4 changes: 4 additions & 0 deletions packages/react-ui/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ export const isKonturIcon = (icon: React.ReactElement) => {
* @returns Nested child text or an empty string
*/
export function getChildrenText(children: React.ReactNode): string {
if (typeof children === 'boolean') {
return '';
}

zhzz marked this conversation as resolved.
Show resolved Hide resolved
if (typeof children === 'string' || typeof children === 'number') {
return children.toString();
}
Expand Down