Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix React.Children.only error when Icon contain children
<Icon>xxx</Icon>
  • Loading branch information
afc163 committed Sep 19, 2018
1 parent 05646e9 commit c21ff52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions components/icon/__tests__/index.test.js
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion components/icon/index.tsx
Expand Up @@ -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.',
);
Expand Down

0 comments on commit c21ff52

Please sign in to comment.