Skip to content

Commit db03b52

Browse files
committed
[gephi-lite] Fix Color picker (#283)
Closing tooltip when mousedown on body instead of click, fix the issue. And change the labels of the color picker button to avoid confusion with their action (ie. close/save/cancel/clear).
1 parent 308de31 commit db03b52

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/gephi-lite/src/components/ColorPicker.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { FC, useRef } from "react";
22
import { SketchPicker } from "react-color";
3+
import { useTranslation } from "react-i18next";
34

45
import { hexToRgba, rgbaToHex } from "../utils/colors";
56
import Tooltip, { TooltipAPI } from "./Tooltip";
6-
import { CheckedIcon, CloseIcon } from "./common-icons";
77

88
export const InlineColorPicker: FC<{ color: string | undefined; onChange: (color: string | undefined) => void }> = ({
99
color,
@@ -36,6 +36,7 @@ const ColorPicker: FC<
3636
| { color: string; onChange: (color: string) => void; clearable?: false }
3737
) & { className?: string }
3838
> = ({ color, onChange, clearable, className }) => {
39+
const { t } = useTranslation();
3940
const tooltipRef = useRef<TooltipAPI>(null);
4041

4142
return (
@@ -51,12 +52,12 @@ const ColorPicker: FC<
5152
<InlineColorPicker onChange={onChange} color={color} />
5253
<div className="text-end gl-gap-1 d-flex justify-content-end">
5354
{clearable && (
54-
<button className="gl-btn gl-btn-icon gl-btn-outline" onClick={() => onChange(undefined)}>
55-
<CloseIcon />
55+
<button className="gl-btn gl-btn-outline" onClick={() => onChange(undefined)}>
56+
{t("common.clear")}
5657
</button>
5758
)}
58-
<button className="gl-btn gl-btn-icon gl-btn-fill" onClick={() => tooltipRef.current?.close()}>
59-
<CheckedIcon />
59+
<button className="gl-btn gl-btn-fill" onClick={() => tooltipRef.current?.close()}>
60+
{t("common.close")}
6061
</button>
6162
</div>
6263
</div>

packages/gephi-lite/src/components/Tooltip.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ const Tooltip = forwardRef<
7272
};
7373

7474
setTimeout(() => {
75-
document.body.addEventListener("click", handleClickBody);
75+
document.body.addEventListener("mousedown", handleClickBody);
7676
}, 0);
7777
return () => {
78-
document.body.removeEventListener("click", handleClickBody);
78+
document.body.removeEventListener("mousedown", handleClickBody);
7979
};
8080
}, [closeOnClickContent, showTooltip]);
8181

0 commit comments

Comments
 (0)