diff --git a/package.json b/package.json index cf259dddaa..312d319f6b 100644 --- a/package.json +++ b/package.json @@ -184,7 +184,6 @@ "rollup-plugin-terser": "^7.0.2", "rollup-plugin-typescript2": "^0.31.2", "semver": "^7.6.3", - "standard-changelog": "^2.0.27", "start-server-and-test": "^1.14.0", "tdesign-icons-view": "^0.3.0", "tdesign-publish-cli": "^0.0.12", diff --git a/site/src/components/codesandbox/content.js b/site/src/components/codesandbox/content.js index 09db21f609..6d4ce19b6b 100644 --- a/site/src/components/codesandbox/content.js +++ b/site/src/components/codesandbox/content.js @@ -80,9 +80,11 @@ export const pkgContent = JSON.stringify( 'react-scripts': '^5.0.0', '@types/react': orgPkg.devDependencies['@types/react'], '@types/react-dom': orgPkg.devDependencies['@types/react-dom'], + lodash: orgPkg.dependencies.lodash, }, devDependencies: { typescript: '^4.4.4', + '@types/lodash': orgPkg.devDependencies['@types/lodash'], }, scripts: { start: 'react-scripts start', diff --git a/src/checkbox/CheckboxGroup.tsx b/src/checkbox/CheckboxGroup.tsx index 399d5e6ee6..eed7e1216f 100644 --- a/src/checkbox/CheckboxGroup.tsx +++ b/src/checkbox/CheckboxGroup.tsx @@ -52,7 +52,10 @@ const CheckboxGroup = (props: const intervalOptions = Array.isArray(options) && options.length > 0 ? options - : React.Children.map(children, (child) => (child as ReactElement).props) || []; + : React.Children.map( + children, + (child: JSX.Element) => child?.type?.displayName === Checkbox.displayName && (child as ReactElement).props, + ) || []; const optionsWithoutCheckAll = intervalOptions.filter((t) => typeof t !== 'object' || !t.checkAll); const optionsWithoutCheckAllValues = []; diff --git a/src/image-viewer/ImageViewer.tsx b/src/image-viewer/ImageViewer.tsx index be6f3e4bf9..5e338c5745 100644 --- a/src/image-viewer/ImageViewer.tsx +++ b/src/image-viewer/ImageViewer.tsx @@ -22,7 +22,7 @@ const ImageViewer: React.FC = (originalProps) => { const imageViewerAttach = useAttach('imageViewer', attach); const [visible, setVisible] = useControlled(props, 'visible', (visible, context) => { - isFunction(props.onClose) && props.onClose(context); + !visible && props?.onClose?.(context); }); const [visibled, setVisibled] = useState(false); diff --git a/src/image-viewer/__tests__/image-viewer.test.tsx b/src/image-viewer/__tests__/image-viewer.test.tsx index 7b9a774bea..050a603237 100644 --- a/src/image-viewer/__tests__/image-viewer.test.tsx +++ b/src/image-viewer/__tests__/image-viewer.test.tsx @@ -29,7 +29,7 @@ describe('ImageViewer', () => { }); // 鼠标点击后,有元素 - expect(onClose).toHaveBeenCalledTimes(1); + expect(onClose).toHaveBeenCalledTimes(0); const imgModal = document.querySelector('.t-image-viewer__modal-pic'); expect(imgModal).toBeTruthy(); @@ -39,7 +39,7 @@ describe('ImageViewer', () => { fireEvent.click(closeBtn); }); // 点击后,没有元素存在 - expect(onClose).toHaveBeenCalledTimes(2); + expect(onClose).toHaveBeenCalledTimes(1); await mockTimeout(() => expect(document.querySelector('.t-image-viewer-preview-image')).toBeNull()); }); @@ -122,7 +122,7 @@ describe('ImageViewerMini', () => { act(() => { fireEvent.click(closeBtn); }); - expect(onClose).toHaveBeenCalledTimes(2); + expect(onClose).toHaveBeenCalledTimes(1); }); }); @@ -153,7 +153,7 @@ describe('ImageViewerModal', () => { // 模拟键盘事件 await user.type(document.body, '{Escape}'); - expect(onClose).toHaveBeenCalledTimes(2); + expect(onClose).toHaveBeenCalledTimes(1); await user.type(document.body, '{ArrowRight}'); expect(onIndexChange).toHaveBeenCalledTimes(1); @@ -166,7 +166,7 @@ describe('ImageViewerModal', () => { act(() => { fireEvent.click(mask); }); - expect(onClose).toHaveBeenCalledTimes(3); + expect(onClose).toHaveBeenCalledTimes(2); }); test('single', async () => {