MCPcopy Create free account
hub / github.com/dailydotdev/apps / SimpleTooltip

Function SimpleTooltip

packages/shared/src/components/tooltips/SimpleTooltip.tsx:19–95  ·  view source on GitHub ↗
({
  show = true,
  children,
  content,
  onTrigger,
  onShow,
  forceLoad,
  ariaLabel,
  ...props
}: TooltipProps & { show?: boolean })

Source from the content-addressed store, hash-verified

17);
18
19export function SimpleTooltip({
20 show = true,
21 children,
22 content,
23 onTrigger,
24 onShow,
25 forceLoad,
26 ariaLabel,
27 ...props
28}: TooltipProps & { show?: boolean }): ReactElement {
29 /**
30 * We introduced the `shouldShow` variable to manage a re-focus issue
31 * The old implementation would re-focus the tooltip whenever a modal would close
32 * Read more on the PR: https://github.com/dailydotdev/apps/pull/713
33 */
34 let shouldShow = true;
35 const component = useMemo(() => {
36 const tooltipProps = {};
37 if (ariaLabel) {
38 tooltipProps['aria-label'] = ariaLabel;
39 } else if (typeof content === 'string') {
40 tooltipProps['aria-label'] = content;
41 }
42
43 return React.cloneElement(children, {
44 ...tooltipProps,
45 ...children.props,
46 });
47 // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
48 // eslint-disable-next-line react-hooks/exhaustive-deps
49 }, [children]);
50
51 const onTooltipTrigger = (inst: TippyInstance, event: Event) => {
52 shouldShow = event.type !== 'focus';
53
54 onTrigger?.(inst, event);
55 };
56
57 const onUntrigger = (_inst: TippyInstance, event: Event) => {
58 const eventPath =
59 (event as Event & { path?: EventTarget[] }).path ||
60 event.composedPath?.();
61 const bodyPath = eventPath.filter(
62 (path: EventTarget) => document.body === path,
63 )[0];
64 if ((bodyPath as HTMLElement)?.className === 'ReactModal__Body--open') {
65 shouldShow = false;
66 return;
67 }
68 shouldShow = true;
69 };
70
71 const onTooltipShow = (inst: TippyInstance) => {
72 if (shouldShow) {
73 return onShow?.(inst);
74 }
75
76 return false;

Callers

nothing calls this directly

Calls 1

getShouldLoadTooltipFunction · 0.90

Tested by

no test coverage detected