Skip to content

Commit 58bf4ac

Browse files
Show tooltip at correct position
1 parent b63bcae commit 58bf4ac

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

portal/src/Tooltip.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,22 @@ export function useTooltipTargetElement(): UseTooltipTargetElementResult {
4343
}
4444

4545
export interface TooltipIconProps {
46+
id?: string;
4647
className?: string;
48+
setRef?: React.RefCallback<unknown>;
4749
}
4850

4951
export function TooltipIcon(props: TooltipIconProps): React.ReactElement {
50-
const { className } = props;
51-
return <Icon className={cn(className, styles.infoIcon)} iconName="info" />;
52+
const { id, setRef, className } = props;
53+
return (
54+
<Icon
55+
id={id}
56+
className={cn(className, styles.infoIcon)}
57+
/* @ts-expect-error */
58+
ref={setRef}
59+
iconName="info"
60+
/>
61+
);
5262
}
5363

5464
const Tooltip: React.FC<TooltipProps> = function Tooltip(props: TooltipProps) {
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
.optionWithTooltip {
2-
display: flex;
3-
flex-direction: row;
4-
}
5-
61
.totpExamples {
72
color: gray;
83
}

portal/src/graphql/portal/ProjectWizardScreen.tsx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ import {
2929
SecondaryAuthenticationMode,
3030
SecondaryAuthenticatorType,
3131
} from "../../types";
32-
import { TooltipIcon } from "../../Tooltip";
32+
import { TooltipIcon, useTooltipTargetElement } from "../../Tooltip";
3333
import ShowLoading from "../../ShowLoading";
3434
import ShowError from "../../ShowError";
3535
import styles from "./ProjectWizardScreen.module.scss";
3636

37+
const TOOLTIP_HOST_STYLES = {
38+
root: {
39+
display: "inline-block",
40+
position: "relative",
41+
},
42+
} as const;
43+
3744
type Step1Answer = "password" | "oob_otp_email";
3845
type Step2Answer = SecondaryAuthenticationMode;
3946
type Step3Answer = SecondaryAuthenticatorType;
@@ -98,6 +105,13 @@ function Step1(props: StepProps) {
98105
[navigate]
99106
);
100107

108+
const { id, setRef, targetElement } = useTooltipTargetElement();
109+
const tooltipProps = useMemo(() => {
110+
return {
111+
targetElement,
112+
};
113+
}, [targetElement]);
114+
101115
const options: IChoiceGroupOption[] = useMemo(() => {
102116
return [
103117
{
@@ -109,15 +123,18 @@ function Step1(props: StepProps) {
109123
text: renderToString("ProjectWizardScreen.step1.option.oob-otp-email"),
110124
onRenderField: (props, render) => {
111125
return (
112-
<TooltipHost
113-
className={styles.optionWithTooltip}
114-
content={renderToString(
115-
"ProjectWizardScreen.step1.tooltip.oob-otp-email"
116-
)}
117-
>
126+
<>
118127
{render!(props)}
119-
<TooltipIcon />
120-
</TooltipHost>
128+
<TooltipHost
129+
styles={TOOLTIP_HOST_STYLES}
130+
tooltipProps={tooltipProps}
131+
content={renderToString(
132+
"ProjectWizardScreen.step1.tooltip.oob-otp-email"
133+
)}
134+
>
135+
<TooltipIcon id={id} setRef={setRef} />
136+
</TooltipHost>
137+
</>
121138
);
122139
},
123140
},
@@ -134,7 +151,7 @@ function Step1(props: StepProps) {
134151
disabled: true,
135152
},
136153
];
137-
}, [renderToString]);
154+
}, [renderToString, id, setRef, tooltipProps]);
138155

139156
const onChange = useCallback(
140157
(_e, option) => {

0 commit comments

Comments
 (0)