aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-06-08 12:07:08 +0200
committerArmand Philippot <git@armandphilippot.com>2022-06-08 12:19:28 +0200
commit58cb40f031f395ca9efccff674ba0f2dae723f50 (patch)
treed69539a66a83da85689b8f7e835492eedc068e1f /src/components/molecules
parent43bddd9506d790ad6707fe71f28a4ecfa635c8f1 (diff)
fix(settings): close tooltip when modal is closing
The event was not captured so the tooltip remained open when the settings was closed. It prevented to click on the toolbar buttons.
Diffstat (limited to 'src/components/molecules')
-rw-r--r--src/components/molecules/forms/fieldset.tsx25
-rw-r--r--src/components/molecules/forms/radio-group.tsx10
2 files changed, 20 insertions, 15 deletions
diff --git a/src/components/molecules/forms/fieldset.tsx b/src/components/molecules/forms/fieldset.tsx
index 670cfa1..dae3ead 100644
--- a/src/components/molecules/forms/fieldset.tsx
+++ b/src/components/molecules/forms/fieldset.tsx
@@ -1,4 +1,4 @@
-import useClickOutside from '@utils/hooks/use-click-outside';
+import useOnClickOutside from '@utils/hooks/use-on-click-outside';
import {
cloneElement,
FC,
@@ -33,11 +33,15 @@ export type FieldsetProps = {
*/
legendClassName?: string;
/**
- * The legend position. Default: stacked.
+ * The legend position.
+ *
+ * @default 'stacked'
*/
legendPosition?: 'inline' | 'stacked';
/**
- * An accessible role. Default: group.
+ * An accessible role.
+ *
+ * @default 'group'
*/
role?: 'group' | 'radiogroup' | 'presentation' | 'none';
/**
@@ -63,7 +67,6 @@ const Fieldset: FC<FieldsetProps> = ({
}) => {
const [isTooltipOpened, setIsTooltipOpened] = useState<boolean>(false);
const buttonRef = useRef<HTMLButtonElement>(null);
- const tooltipRef = useRef<HTMLDivElement>(null);
const wrapperModifier = `wrapper--${legendPosition}`;
const buttonModifier = isTooltipOpened ? styles['btn--activated'] : '';
const legendModifier =
@@ -73,19 +76,17 @@ const Fieldset: FC<FieldsetProps> = ({
: 'tooltip--hidden';
/**
- * Close the tooltip if the event target is outside.
+ * Close the tooltip if the target is not the button.
*
- * @param {EventTarget} target - The event target.
+ * @param {Node} target - The event target.
*/
- const closeTooltip = (target: EventTarget) => {
- if (buttonRef.current && !buttonRef.current.contains(target as Node))
+ const closeTooltip = (target: Node) => {
+ if (buttonRef.current && !buttonRef.current.contains(target)) {
setIsTooltipOpened(false);
+ }
};
- useClickOutside(
- tooltipRef,
- (target) => isTooltipOpened && closeTooltip(target)
- );
+ const tooltipRef = useOnClickOutside<HTMLDivElement>(closeTooltip);
return (
<fieldset
diff --git a/src/components/molecules/forms/radio-group.tsx b/src/components/molecules/forms/radio-group.tsx
index 64bdaa0..134829f 100644
--- a/src/components/molecules/forms/radio-group.tsx
+++ b/src/components/molecules/forms/radio-group.tsx
@@ -2,7 +2,7 @@ import Fieldset, {
type FieldsetProps,
} from '@components/molecules/forms/fieldset';
import useStateChange from '@utils/hooks/use-state-change';
-import { ChangeEvent, FC, MouseEvent, SetStateAction, useState } from 'react';
+import { ChangeEvent, FC, MouseEvent, SetStateAction } from 'react';
import LabelledBooleanField, {
type LabelledBooleanFieldProps,
} from './labelled-boolean-field';
@@ -37,11 +37,15 @@ export type RadioGroupProps = Pick<
*/
initialChoice: string;
/**
- * The radio group kind. Default: regular.
+ * The radio group kind.
+ *
+ * @default 'regular
*/
kind?: 'regular' | 'toggle';
/**
- * The legend position. Default: inline.
+ * The legend position.
+ *
+ * @default 'inline'
*/
legendPosition?: FieldsetProps['legendPosition'];
/**