-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COM-162: Add EllipsisTooltip
component to admin
#1548
Conversation
c71d745
to
a41ebbd
Compare
a41ebbd
to
e2483d8
Compare
f1f61cd
to
c7442a0
Compare
c7442a0
to
2fe2fc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure about the name of the component. Ellipsis is a technical term for overflowing text content, but the content of this component could be anything, right? Maybe we could use a more generic name, like <Overflowable>
, HandleOverflow
or similar? 🤔
{renderWithTooltip ? ( | ||
<Tooltip PopperProps={{ anchorEl: rootRef.current }} title={children}> | ||
{content} | ||
</Tooltip> | ||
) : ( | ||
content | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this conditional render you could render the Tooltip all the time and use undefined
for title
if the content fits into the container. I believe this would simplify the ref handling
const updateRenderWithTooltip = React.useCallback(() => { | ||
if (rootRef.current && contentRef.current) { | ||
setRenderWithTooltip(contentRef.current.offsetWidth > rootRef.current.clientWidth); | ||
} | ||
// The dependency array items must be `.current`, otherwise the callback will not be called, when the html-element is rendered. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [rootRef.current, contentRef.current]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could define the function inside the useEffect for simplicity. Also, if you always render the tooltip, the refs wouldn't need to be in the dependency array
Used to automatically add a tooltip to text that is too long to fit in its container.
This is useful for displaying text in a table or data grid when the text might be too long to fit in the column.
Theming-Support is added in a separate PR (#1551 ) because of the theming-refactor (#1376).