From ed4766188dfd963473d19fb12e206e7a46d31fa7 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Mon, 20 May 2024 16:37:53 -0400 Subject: [PATCH] fix(ui): tooltip positioning issues (#6439) --- packages/richtext-lexical/src/field/Field.tsx | 12 +- .../features/blocks/component/index.scss | 4 - .../richtext-lexical/src/field/index.scss | 2 - .../richtext-slate/src/field/RichText.tsx | 12 +- packages/ui/src/elements/Tooltip/index.scss | 8 +- packages/ui/src/elements/Tooltip/index.tsx | 45 ++-- packages/ui/src/fields/Array/index.scss | 4 - packages/ui/src/fields/Array/index.tsx | 6 +- packages/ui/src/fields/Blocks/index.scss | 4 - packages/ui/src/fields/Blocks/index.tsx | 6 +- packages/ui/src/fields/Checkbox/index.scss | 4 - packages/ui/src/fields/Checkbox/index.tsx | 4 +- packages/ui/src/fields/Code/index.tsx | 4 +- .../ui/src/fields/ConfirmPassword/index.tsx | 22 +- packages/ui/src/fields/DateTime/index.scss | 6 - packages/ui/src/fields/DateTime/index.tsx | 6 +- packages/ui/src/fields/Email/index.tsx | 4 +- packages/ui/src/fields/JSON/index.tsx | 5 +- packages/ui/src/fields/Number/index.tsx | 108 +++++----- packages/ui/src/fields/Password/index.tsx | 23 ++- packages/ui/src/fields/RadioGroup/index.scss | 4 - packages/ui/src/fields/RadioGroup/index.tsx | 81 ++++---- packages/ui/src/fields/Relationship/index.tsx | 193 +++++++++--------- packages/ui/src/fields/Select/index.tsx | 5 +- packages/ui/src/fields/Text/Input.tsx | 95 ++++----- packages/ui/src/fields/Textarea/Input.tsx | 50 ++--- packages/ui/src/fields/Upload/Input.tsx | 89 ++++---- packages/ui/src/forms/FieldError/index.scss | 3 +- packages/ui/src/forms/FieldError/index.tsx | 4 +- packages/ui/src/forms/RenderFields/index.scss | 5 + packages/ui/src/hooks/useIntersect.ts | 2 +- 31 files changed, 409 insertions(+), 411 deletions(-) diff --git a/packages/richtext-lexical/src/field/Field.tsx b/packages/richtext-lexical/src/field/Field.tsx index 284ed3466e..73bf0e3167 100644 --- a/packages/richtext-lexical/src/field/Field.tsx +++ b/packages/richtext-lexical/src/field/Field.tsx @@ -84,14 +84,14 @@ const _RichText: React.FC< width, }} > +
- {}}> +
- = (props) => { @@ -21,6 +25,7 @@ export const Tooltip: React.FC = (props) => { className, delay = 350, show: showFromProps = true, + staticPositioning = false, } = props const [show, setShow] = React.useState(showFromProps) @@ -28,11 +33,14 @@ export const Tooltip: React.FC = (props) => { const getTitleAttribute = (content) => (typeof content === 'string' ? content : '') - const [ref, intersectionEntry] = useIntersect({ - root: boundingRef?.current || null, - rootMargin: '-145px 0px 0px 100px', - threshold: 0, - }) + const [ref, intersectionEntry] = useIntersect( + { + root: boundingRef?.current || null, + rootMargin: '-145px 0px 0px 100px', + threshold: 0, + }, + staticPositioning, + ) useEffect(() => { let timerId: NodeJS.Timeout @@ -52,22 +60,25 @@ export const Tooltip: React.FC = (props) => { }, [showFromProps, delay]) useEffect(() => { + if (staticPositioning) return setPosition(intersectionEntry?.isIntersecting ? 'top' : 'bottom') - }, [intersectionEntry]) + }, [intersectionEntry, staticPositioning]) + // The first aside is always on top. The purpose of that is that it can reliably be used for the interaction observer (as it's not moving around), to calculate the position of the actual tooltip. return ( - - + {!staticPositioning && ( + + )}