fix: tip direction

This commit is contained in:
kangwei 2020-05-10 21:36:43 +08:00
parent bd49e50295
commit f51d496860
2 changed files with 12 additions and 3 deletions

View File

@ -64,8 +64,17 @@ function resolveDirection(popup: any, target: any, edge: any, bounds: any, prefe
return prefer;
}
function resolvePrefer(prefer: any) {
function resolvePrefer(prefer: any, targetRect: any, bounds: any) {
if (!prefer) {
if (targetRect.left - bounds.left < 10) {
return { dir: 'right' };
} else if (targetRect.top - bounds.top < 10) {
return { dir: 'bottom' };
} else if (bounds.bottom - targetRect.bottom < 10) {
return { dir: 'top' };
} else if (bounds.right - targetRect.right < 10) {
return { dir: 'left' };
}
return {};
}
const force = prefer[0] === '!';
@ -105,7 +114,7 @@ export function resolvePosition(popup: any, target: any, arrow: any, bounds: any
width: popup.width,
};
const prefers = resolvePrefer(prefer);
const prefers = resolvePrefer(prefer, target, bounds);
const edge = resolveEdge(popup, target, arrow, bounds);

View File

@ -27,7 +27,7 @@ export class Title extends Component<{ title: TitleContent; className?: string;
typeof title.tip === 'object' && !(isValidElement(title.tip) || isI18nData(title.tip))
? title.tip
: { children: title.tip };
tip = <Tip direction="top" theme="black" {...tipProps} />;
tip = <Tip {...tipProps} />;
}
}