Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Allow changing conditional formatting to color range when rule condition is set (#71079)

Kevin Kelleher07f25c0cc795
diff --git a/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.tsx b/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.tsx
index eb01d1d9362..652854ce193 100644
--- a/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.tsx
+++ b/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.tsx
@@ -54,7 +54,7 @@ export function TextInputBlurChange<T extends TextInputProps = TextInputProps>({
(event: FocusEvent<HTMLInputElement>) => {
onBlur?.(event);
- if (onBlurChange && (value || "") !== event.target.value) {
+ if (onBlurChange && String(value ?? "") !== event.target.value) {
onBlurChange(event);
setInternalValue(normalize(event.target.value) ?? undefined);
}
@@ -73,7 +73,7 @@ export function TextInputBlurChange<T extends TextInputProps = TextInputProps>({
);
useUnmountLayout(() => {
- const lastPropsValue = value || "";
+ const lastPropsValue = String(value ?? "");
const currentValue = ref.current?.value || "";
if (onBlurChange && ref.current && lastPropsValue !== currentValue) {
diff --git a/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.unit.spec.tsx b/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.unit.spec.tsx
index 2f756e3df97..b4af0d7f190 100644
--- a/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.unit.spec.tsx
+++ b/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.unit.spec.tsx
@@ -55,6 +55,14 @@ describe("TextInputBlurChange", () => {
expect(onBlurChange.mock.results[0].value).toBe("test");
});
+ it("should not trigger onBlurChange if the value hasn't changed", async () => {
+ const { onBlurChange } = setup({ value: 5 }); // should handle numeric values as well
+
+ cleanup();
+
+ expect(onBlurChange).toHaveBeenCalledTimes(0);
+ });
+
it("should set `internalValue` to the normalized value even if the normalized value is the same as the previous one", async () => {
const value = "/";
setup({ value, normalize: (value) => (value as string).trim() });
diff --git a/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.tsx b/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.tsx
index b7766731946..a72f134f9c2 100644
--- a/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.tsx
+++ b/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.tsx
@@ -55,7 +55,7 @@ export function TextareaBlurChange<T extends TextareaProps = TextareaProps>({
(event: FocusEvent<HTMLTextAreaElement>) => {
onBlur?.(event);
- if (onBlurChange && (value || "") !== event.target.value) {
+ if (onBlurChange && String(value ?? "") !== event.target.value) {
onBlurChange(event);
setInternalValue(normalize(event.target.value) ?? undefined);
}
@@ -74,7 +74,7 @@ export function TextareaBlurChange<T extends TextareaProps = TextareaProps>({
);
useUnmountLayout(() => {
- const lastPropsValue = value || "";
+ const lastPropsValue = String(value ?? "");
const currentValue = ref.current?.value || "";
if (ref.current && lastPropsValue !== currentValue) {
diff --git a/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.unit.spec.tsx b/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.unit.spec.tsx
index 2497e52d07c..f8d1f4a17d3 100644
--- a/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.unit.spec.tsx
+++ b/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.unit.spec.tsx
@@ -55,6 +55,14 @@ describe("TextareaBlurChange", () => {
expect(onBlurChange.mock.results[0].value).toBe("test");
});
+ it("should not trigger onBlurChange if the value hasn't changed", async () => {
+ const { onBlurChange } = setup({ value: 5 }); // should handle numeric values as well
+
+ cleanup();
+
+ expect(onBlurChange).toHaveBeenCalledTimes(0);
+ });
+
it("should set `internalValue` to the normalized value even if the normalized value is the same as the previous one", async () => {
const value = "/";
setup({ value, normalize: (value) => (value as string).trim() });