diff --git a/src/Popup.tsx b/src/Popup.tsx
index 7447d85..069e6b9 100644
--- a/src/Popup.tsx
+++ b/src/Popup.tsx
@@ -11,53 +11,22 @@ export interface ContentProps {
bodyClassName?: string;
}
-const getTextContent = (node: (() => React.ReactNode) | React.ReactNode): string => {
- if (!node) {
- return '';
- }
-
- const resolvedNode = typeof node === 'function' ? node() : node;
-
- if (typeof resolvedNode === 'string' || typeof resolvedNode === 'number') {
- return String(resolvedNode);
- }
-
- if (Array.isArray(resolvedNode)) {
- return resolvedNode.map(getTextContent).join(' ');
- }
-
- if (React.isValidElement(resolvedNode)) {
- return getTextContent(resolvedNode.props.children);
- }
-
- return '';
-};
-
export default function Popup(props: ContentProps) {
const { children, prefixCls, id, overlayInnerStyle: innerStyle, bodyClassName, className, style } =
props;
- const tooltipText = getTextContent(children);
-
return (
<>
{typeof children === 'function' ? children() : children}
- {tooltipText && (
-
- {tooltipText}
-
- )}
>
);
}
diff --git a/tests/popup.test.tsx b/tests/popup.test.tsx
index 7165d21..52a97f3 100644
--- a/tests/popup.test.tsx
+++ b/tests/popup.test.tsx
@@ -1,5 +1,3 @@
-import React from 'react';
-import { render } from '@testing-library/react';
import Popup from '../src/Popup';
describe('Popup', () => {
@@ -7,94 +5,4 @@ describe('Popup', () => {
it('should export', () => {
expect(Popup).toBeTruthy();
});
-
- it('should correctly extract text from string, number, function, and element', () => {
- const { getByRole } = render(
- ,
- );
-
- const tooltip = getByRole('tooltip');
- const hiddenTextContainer = tooltip.querySelector('div > div');
-
- expect(hiddenTextContainer.textContent).toBe('Hello 123 World');
- });
-
- it('should apply updated hidden text styles correctly', () => {
- const { getByRole } = render(
- ,
- );
-
- const tooltip = getByRole('tooltip');
- const hiddenTextContainer = tooltip.querySelector('div > div');
-
- expect(hiddenTextContainer).toHaveStyle({
- width: '0',
- height: '0',
- position: 'absolute',
- overflow: 'hidden',
- opacity: '0',
- });
- });
-
- it('should return empty string if children is null or undefined', () => {
- const { getByRole } = render(
- ,
- );
- const tooltip = getByRole('tooltip');
-
- expect(tooltip.querySelector('div > div')).toBeNull();
- });
-
- it('should handle nested arrays correctly', () => {
- const { getByRole } = render(
- ,
- );
- const tooltip = getByRole('tooltip');
- const hiddenTextContainer = tooltip.querySelector('div > div');
-
- // "First Second Third Fourth"
- expect(hiddenTextContainer.textContent).toBe('First Second Third Fourth');
- });
-
- it('should handle function returning an array', () => {
- const { getByRole } = render(
- ,
- );
- const tooltip = getByRole('tooltip');
- const hiddenTextContainer = tooltip.querySelector('div > div');
-
- // "Alpha Beta"
- expect(hiddenTextContainer.textContent).toBe('Alpha Beta');
- });
-
- it('should handle function returning undefined', () => {
- const { getByRole } = render(
- ,
- );
- const tooltip = getByRole('tooltip');
-
- expect(tooltip.querySelector('div > div')).toBeNull();
- });
});