Skip to content

Commit

Permalink
fix(switch): fix switch of displayName (#1983)
Browse files Browse the repository at this point in the history
Co-authored-by: maxin <maxin@growingio.com>
  • Loading branch information
nnmax and maxin committed Apr 21, 2022
1 parent 6a4a3a8 commit 31d03a5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/switch/Switch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import classnames from 'classnames';
import { isUndefined } from 'lodash';
import { get, isUndefined } from 'lodash';
import { usePrefixCls } from '@gio-design/utils';
import usePrevious from '../utils/hooks/usePrevious';
import filterChildren from '../utils/filterChildren';
Expand Down Expand Up @@ -36,7 +36,7 @@ const Switch = React.forwardRef<HTMLDivElement, SwitchProps>((props: SwitchProps
const getChildrenItems = () =>
filterChildren(children, (child) => {
if (React.isValidElement(child)) {
if (typeof child.type !== 'object' || (child.type as typeof SwitchItem).displayName !== 'Switch') {
if (typeof child.type !== 'object' || get(child, 'type.displayName') !== SwitchItem.displayName) {
return false;
}
if (!Reflect.has(child.props, 'value')) {
Expand Down
2 changes: 1 addition & 1 deletion src/switch/demo/Switch.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ const JSXTemplateGroup: Story<SwitchProps> = (args) => {
<>
<Switch {...args} size="normal" value={selectedValue} onChange={onChange}>
{tabs.map((t) => (
<Switch.Item value={t.value} prefix={<PushMsgFilled />}>
<Switch.Item value={t.value} key={t.key} prefix={<PushMsgFilled />}>
{t.value}
</Switch.Item>
))}
Expand Down

1 comment on commit 31d03a5

@vercel
Copy link

@vercel vercel bot commented on 31d03a5 Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

gio-design – ./

gio-design.vercel.app
gio-design-git-master-growingio.vercel.app
gio-design-growingio.vercel.app

Please sign in to comment.