Skip to content

Commit

Permalink
fix: Tooltip/Popover children type
Browse files Browse the repository at this point in the history
close #26517
  • Loading branch information
afc163 committed Sep 2, 2020
1 parent c88fd34 commit b78e230
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion components/popconfirm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ const Popconfirm = React.forwardRef<unknown, PopconfirmProps>((props, ref) => {
>
{cloneElement(children, {
onKeyDown: (e: React.KeyboardEvent<any>) => {
children?.props.onKeyDown?.(e);
if (React.isValidElement(children)) {
children?.props.onKeyDown?.(e);
}
onKeyDown(e);
},
})}
Expand Down
16 changes: 16 additions & 0 deletions components/tooltip/__tests__/type.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import Tooltip from '..';

describe('Tooltip.typescript', () => {
it('Tooltip children should accept ReactNode', () => {
const tooltip = (
<Tooltip title="title">
<div />
<div />
</Tooltip>
);
const tooltip2 = <Tooltip title="title">{null}</Tooltip>;
expect(tooltip).toBeTruthy();
expect(tooltip2).toBeTruthy();
});
});
5 changes: 3 additions & 2 deletions components/tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface TooltipAlignConfig {
useCssTransform?: boolean;
}

export interface AbstractTooltipProps extends Partial<RcTooltipProps> {
export interface AbstractTooltipProps extends Partial<Omit<RcTooltipProps, 'children'>> {
style?: React.CSSProperties;
className?: string;
color?: LiteralUnion<PresetColorType, string>;
Expand All @@ -47,6 +47,7 @@ export interface AbstractTooltipProps extends Partial<RcTooltipProps> {
arrowPointAtCenter?: boolean;
autoAdjustOverflow?: boolean | AdjustOverflow;
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
children?: React.ReactNode;
}

export type RenderFunction = () => React.ReactNode;
Expand Down Expand Up @@ -211,8 +212,8 @@ const Tooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
overlayClassName,
color,
overlayInnerStyle,
children,
} = props;
const children = props.children as React.ReactElement<any>;
const prefixCls = getPrefixCls('tooltip', customizePrefixCls);
let tempVisible = visible;
// Hide tooltip when there is no title
Expand Down

0 comments on commit b78e230

Please sign in to comment.