Skip to content
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

Solution for tc-tooltip issues with disabled components #257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/src/components/controls/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import RcTooltip from 'rc-tooltip';

type TooltipProps = {
title: string,
identifier?: string;
placement?: 'left' | 'right' | 'top' | 'bottom' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight',
children: ReactElement,
mouseEnterDelay?: number;
Expand All @@ -13,8 +14,9 @@ type TooltipProps = {
// --> The user can craft a malicious script with the NotesModalButton and this will just execute it!


export const Tooltip = ({children, title, placement = 'left', mouseEnterDelay = 0.6}: TooltipProps) => (
export const Tooltip = ({children, title, placement = 'left', mouseEnterDelay = 0.6, identifier = ''}: TooltipProps) => (
<RcTooltip
overlayClassName={identifier}
placement={placement} // ['left','right','top','bottom', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight']
trigger={['hover'/* , 'click', 'focus' */]}
overlay={<div dangerouslySetInnerHTML={{__html: title}} />}
Expand Down
23 changes: 21 additions & 2 deletions frontend/src/components/controls/form-controls/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,35 @@ const ButtonComponent = ({variant = 'primary', size = 'md', disabled, className,
if (disabled) {
// WORKAROUND: Tooltip not going away when the button is disabled
// https://github.com/react-component/tooltip/issues/18#issuecomment-411476678
const identifier = Math.floor(Math.random() * Date.now()).toString(36)
FinalButton = (
<Tooltip title={title}>
<Tooltip
title={title}
identifier={identifier}
>
<div>
<ReactButton
className={className}
variant={variant}
size={size === 'md' ? undefined : size}
onClick={realClick}
disabled={disabled}
active={false}
disabled={true}
style={{...style, pointerEvents: 'none'}}
onPointerLeave={()=>{
const tooltips = document.getElementsByClassName(identifier);
for(let i = 0; i < tooltips.length; i++)
{
tooltips[i].classList.add("rc-tooltip-hidden");
}
}}
onPointerEnter={()=>{
const tooltips = document.getElementsByClassName(identifier);
for(let i = 0; i < tooltips.length; i++)
{
tooltips[i].classList.remove("rc-tooltip-hidden");
}
}}
{...rest}
>
{icon ? <Icon fa={icon} size={1} style={{marginRight: children ? 6 : 0}} /> : null}
Expand Down