Skip to content

Commit 7859ae3

Browse files
refactor: position must have x and y
1 parent fae8796 commit 7859ae3

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function WithProviderMultiple() {
4242
function App() {
4343
const [anchorId, setAnchorId] = useState('button')
4444
const [isDarkOpen, setIsDarkOpen] = useState(false)
45-
const [position, setPosition] = useState<IPosition>({})
45+
const [position, setPosition] = useState<IPosition>({ x: 0, y: 0 })
4646

4747
const handlePositionClick: React.MouseEventHandler<HTMLDivElement> = (event) => {
4848
const x = event.clientX

src/components/Tooltip/Tooltip.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const Tooltip = ({
102102
}
103103

104104
const handleTooltipPosition = () => {
105-
if (!position?.x || !position?.y) {
105+
if (!position) {
106106
return
107107
}
108108

@@ -120,7 +120,7 @@ const Tooltip = ({
120120
}
121121
},
122122
} as Element
123-
123+
setCalculatingPosition(true)
124124
computeTooltipPosition({
125125
place,
126126
offset,
@@ -210,7 +210,8 @@ const Tooltip = ({
210210
}, [anchorRefs, activeAnchor, anchorId, events, delayHide, delayShow])
211211

212212
useEffect(() => {
213-
if (position?.x && position?.y) {
213+
if (position) {
214+
// if `position` is set, override regular positioning
214215
handleTooltipPosition()
215216
return () => null
216217
}

src/components/Tooltip/TooltipTypes.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export type DataAttribute =
2525
| 'delay-hide'
2626

2727
export interface IPosition {
28-
x?: number
29-
y?: number
28+
x: number
29+
y: number
3030
}
3131

3232
export interface ITooltip {

0 commit comments

Comments
 (0)