Skip to content

Commit 499be17

Browse files
committed
docs: handle step tooltip bug in safari
1 parent 4bc3f5b commit 499be17

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

www/packages/docs-ui/src/components/WorkflowDiagram/Common/Node/index.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import React, { useEffect, useMemo, useRef, useState } from "react"
77
import { WorkflowStepUi } from "types"
88
import { InlineCode, MarkdownContent, Tooltip } from "../../.."
99
import { Bolt, InformationCircle } from "@medusajs/icons"
10+
import { getBrowser } from "../../../../utils"
1011

1112
export type WorkflowDiagramNodeProps = {
1213
step: WorkflowStepUi
@@ -34,12 +35,22 @@ export const WorkflowDiagramStepNode = ({ step }: WorkflowDiagramNodeProps) => {
3435
return
3536
}
3637

38+
const firstChild = nodeParent.firstChild as HTMLElement
39+
3740
const nodeBoundingRect = nodeParent.getBoundingClientRect()
3841
const diagramBoundingRect = diagramParent.getBoundingClientRect()
42+
const browser = getBrowser()
3943

40-
setOffset(
41-
Math.max(diagramBoundingRect.width - nodeBoundingRect.width + 10, 10)
42-
)
44+
if (browser === "Safari") {
45+
// React Tooltip has a bug in Safari where the offset is not calculated correctly
46+
// when place is set.
47+
const firstChildBoundingRect = firstChild.getBoundingClientRect()
48+
setOffset(diagramBoundingRect.width - firstChildBoundingRect.width + 20)
49+
} else {
50+
setOffset(
51+
Math.max(diagramBoundingRect.width - nodeBoundingRect.width + 10, 10)
52+
)
53+
}
4354
}, [ref.current])
4455

4556
return (

www/packages/docs-ui/src/utils/get-os-shortcut.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

www/packages/docs-ui/src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export * from "./decode-str"
55
export * from "./dom-utils"
66
export * from "./get-link-with-base-path"
77
export * from "./get-navbar-items"
8-
export * from "./get-os-shortcut"
8+
export * from "./os-browser-utils"
99
export * from "./get-scrolled-top"
1010
export * from "./is-elm-window"
1111
export * from "./is-in-view"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export function getBrowser():
2+
| "Chrome"
3+
| "Safari"
4+
| "Firefox"
5+
| "Internet Explorer"
6+
| "Edge"
7+
| "unknown" {
8+
if (typeof navigator === "undefined") {
9+
return "unknown"
10+
}
11+
12+
const userAgent = navigator.userAgent.toLowerCase()
13+
14+
if (userAgent.indexOf("chrome") > -1) {
15+
return "Chrome"
16+
} else if (userAgent.indexOf("safari") > -1) {
17+
return "Safari"
18+
} else if (userAgent.indexOf("firefox") > -1) {
19+
return "Firefox"
20+
} else if (
21+
userAgent.indexOf("msie") > -1 ||
22+
userAgent.indexOf("trident") > -1
23+
) {
24+
return "Internet Explorer"
25+
} else if (userAgent.indexOf("edge") > -1) {
26+
return "Edge"
27+
} else {
28+
return "unknown"
29+
}
30+
}
31+
32+
export function getOsShortcut() {
33+
const isMacOs =
34+
typeof navigator !== "undefined"
35+
? navigator.userAgent.toLowerCase().indexOf("mac") !== 0
36+
: true
37+
38+
return isMacOs ? "⌘" : "Ctrl"
39+
}

0 commit comments

Comments
 (0)