-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tooltip] Add placement
followCursor
(#22876)
Co-authored-by: Sebastian Silbermann <[email protected]> Co-authored-by: Olivier Tassinari <[email protected]>
- Loading branch information
1 parent
cb6b69b
commit 4084299
Showing
10 changed files
with
248 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as React from 'react'; | ||
import Box from '@material-ui/core/Box'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
|
||
export default function AnchorElTooltips() { | ||
const positionRef = React.useRef({ | ||
x: 0, | ||
y: 0, | ||
}); | ||
|
||
const popperRef = React.useRef(null); | ||
const areaRef = React.useRef(null); | ||
|
||
const handleMouseMove = (event) => { | ||
positionRef.current = { x: event.clientX, y: event.clientY }; | ||
|
||
if (popperRef.current != null) { | ||
popperRef.current.scheduleUpdate(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Tooltip | ||
title="Add" | ||
placement="top" | ||
arrow | ||
PopperProps={{ | ||
popperRef, | ||
anchorEl: { | ||
clientHeight: 0, | ||
clientWidth: 0, | ||
getBoundingClientRect: () => ({ | ||
top: areaRef.current?.getBoundingClientRect().top ?? 0, | ||
left: positionRef.current.x, | ||
right: positionRef.current.x, | ||
bottom: areaRef.current?.getBoundingClientRect().bottom ?? 0, | ||
width: 0, | ||
height: 0, | ||
}), | ||
}, | ||
}} | ||
> | ||
<Box | ||
/* @ts-expect-error need to fix #17010 */ | ||
ref={areaRef} | ||
bgcolor="primary.main" | ||
color="primary.contrastText" | ||
onMouseMove={handleMouseMove} | ||
p={2} | ||
> | ||
Hover | ||
</Box> | ||
</Tooltip> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as React from 'react'; | ||
import Box from '@material-ui/core/Box'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
import PopperJs from 'popper.js'; | ||
|
||
export default function AnchorElTooltips() { | ||
const positionRef = React.useRef<{ x: number; y: number }>({ | ||
x: 0, | ||
y: 0, | ||
}); | ||
const popperRef = React.useRef<PopperJs>(null); | ||
const areaRef = React.useRef<HTMLDivElement>(null); | ||
|
||
const handleMouseMove = (event: React.MouseEvent) => { | ||
positionRef.current = { x: event.clientX, y: event.clientY }; | ||
|
||
if (popperRef.current != null) { | ||
popperRef.current.scheduleUpdate(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Tooltip | ||
title="Add" | ||
placement="top" | ||
arrow | ||
PopperProps={{ | ||
popperRef, | ||
anchorEl: { | ||
clientHeight: 0, | ||
clientWidth: 0, | ||
getBoundingClientRect: () => ({ | ||
top: areaRef.current?.getBoundingClientRect().top ?? 0, | ||
left: positionRef.current.x, | ||
right: positionRef.current.x, | ||
bottom: areaRef.current?.getBoundingClientRect().bottom ?? 0, | ||
width: 0, | ||
height: 0, | ||
}), | ||
}, | ||
}} | ||
> | ||
<Box | ||
/* @ts-expect-error need to fix #17010 */ | ||
ref={areaRef} | ||
bgcolor="primary.main" | ||
color="primary.contrastText" | ||
onMouseMove={handleMouseMove} | ||
p={2} | ||
> | ||
Hover | ||
</Box> | ||
</Tooltip> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
docs/src/pages/components/tooltips/FollowCursorTooltips.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react'; | ||
import Box from '@material-ui/core/Box'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
|
||
export default function FollowCursorTooltips() { | ||
return ( | ||
<Tooltip title="You don't have permission to do this" followCursor> | ||
<Box bgcolor="text.disabled" color="background.paper" p={2}> | ||
Disabled Action | ||
</Box> | ||
</Tooltip> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
docs/src/pages/components/tooltips/FollowCursorTooltips.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react'; | ||
import Box from '@material-ui/core/Box'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
|
||
export default function FollowCursorTooltips() { | ||
return ( | ||
<Tooltip title="You don't have permission to do this" followCursor> | ||
<Box bgcolor="text.disabled" color="background.paper" p={2}> | ||
Disabled Action | ||
</Box> | ||
</Tooltip> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters