diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-21 16:04:06 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-21 19:24:48 +0200 |
| commit | ef2407832202e5451751e26459e6bdcdbd152122 (patch) | |
| tree | d7fe063755168619cba78425cb7794807d954d84 /src/components/molecules/buttons/help-button.tsx | |
| parent | e305cbbdbc49af575e25957f6ab72ccf944339ec (diff) | |
fix: close Ackee tooltip on button click
The tooltip was closing and reopening on click because of a conflict
between the button event and the hook useClickOutside. By checking that
the event target is not the button, the tooltip is now closing as
expected.
Diffstat (limited to 'src/components/molecules/buttons/help-button.tsx')
| -rw-r--r-- | src/components/molecules/buttons/help-button.tsx | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/components/molecules/buttons/help-button.tsx b/src/components/molecules/buttons/help-button.tsx index f19322f..e351453 100644 --- a/src/components/molecules/buttons/help-button.tsx +++ b/src/components/molecules/buttons/help-button.tsx @@ -1,5 +1,5 @@ import Button, { type ButtonProps } from '@components/atoms/buttons/button'; -import { FC } from 'react'; +import { forwardRef, ForwardRefRenderFunction } from 'react'; import { useIntl } from 'react-intl'; import styles from './help-button.module.scss'; @@ -15,7 +15,10 @@ export type HelpButtonProps = Pick<ButtonProps, 'onClick'> & { * * Render a button with an interrogation mark icon. */ -const HelpButton: FC<HelpButtonProps> = ({ className = '', onClick }) => { +const HelpButton: ForwardRefRenderFunction< + HTMLButtonElement, + HelpButtonProps +> = ({ className = '', onClick }, ref) => { const intl = useIntl(); const text = intl.formatMessage({ defaultMessage: 'Help', @@ -25,9 +28,10 @@ const HelpButton: FC<HelpButtonProps> = ({ className = '', onClick }) => { return ( <Button - shape="circle" className={`${styles.btn} ${className}`} onClick={onClick} + ref={ref} + shape="circle" > <span className="screen-reader-text">{text}</span> <span className={styles.icon}>?</span> @@ -35,4 +39,4 @@ const HelpButton: FC<HelpButtonProps> = ({ className = '', onClick }) => { ); }; -export default HelpButton; +export default forwardRef(HelpButton); |
