Permalink
Browse files

Fix React.Children.only error when Icon contain children

<Icon>xxx</Icon>
  • Loading branch information...
afc163 committed Sep 19, 2018
1 parent 05646e9 commit c21ff5251d1ff0f00d7f283dd377a7b13eec21ee
Showing with 11 additions and 1 deletion.
  1. +6 −0 components/icon/__tests__/index.test.js
  2. +5 −1 components/icon/index.tsx
@@ -96,6 +96,12 @@ describe('Icon', () => {
expect(wrapper.instance().tooltip.props.visible).toBe(false);
});

it('should support custom usage of children', () => {
expect(() => {
render(<Icon type="custom">&E648</Icon>);
}).not.toThrow();
});

describe('`component` prop', () => {
it('can access to svg defs if has children', () => {
const wrapper = render(
@@ -99,7 +99,11 @@ const Icon: React.SFC<IconProps> = (props) => {

if (children) {
warning(
Boolean(viewBox) || React.Children.count(children) === 1 && React.Children.only(children).type === 'use',
Boolean(viewBox) || (
React.Children.count(children) === 1 &&
React.isValidElement(children) &&
React.Children.only(children).type === 'use'
),
'Make sure that you provide correct `viewBox`' +
' prop (default `0 0 1024 1024`) to the icon.',
);

0 comments on commit c21ff52

Please sign in to comment.