diff --git a/components/button/__tests__/__snapshots__/index.test.tsx.snap b/components/button/__tests__/__snapshots__/index.test.tsx.snap index e7e2d9a370..c40a35e53a 100644 --- a/components/button/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/button/__tests__/__snapshots__/index.test.tsx.snap @@ -263,6 +263,17 @@ exports[`Button rtl render component should be rendered correctly in RTL directi /> `; +exports[`Button should handle fragment as children 1`] = ` + +`; + exports[`Button should merge text if children using variable 1`] = ` , + ); + expect(wrapper).toMatchRenderedSnapshot(); + }); }); diff --git a/components/button/button.tsx b/components/button/button.tsx index 4a8a2b4566..2aa8a5fe1d 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -22,6 +22,10 @@ function isUnborderedButtonType(type: ButtonType | undefined) { return type === 'text' || type === 'link'; } +function isReactFragment(node: React.ReactNode) { + return React.isValidElement(node) && node.type === React.Fragment; +} + // Insert one space between two chinese characters automatically. function insertSpace(child: React.ReactChild, needInserted: boolean) { // Check the child if is undefined or null. @@ -41,9 +45,9 @@ function insertSpace(child: React.ReactChild, needInserted: boolean) { }); } if (typeof child === 'string') { - if (isTwoCNChar(child)) { - child = child.split('').join(SPACE); - } + return isTwoCNChar(child) ? {child.split('').join(SPACE)} : {child}; + } + if (isReactFragment(child)) { return {child}; } return child;