Skip to content

Commit c52b1d6

Browse files
committed
fix: fix stale setValue reference
1 parent d8460bf commit c52b1d6

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

packages/pluggableWidgets/color-picker-web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- We fixed an issue where the widget would still change values in the previous Data View context after a context switch in the "listen to widget" setup.
12+
913
## [2.1.4] - 2026-02-09
1014

1115
### Added

packages/pluggableWidgets/color-picker-web/src/components/ColorPicker.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ export const ColorPicker = (props: ColorPickerProps): ReactElement => {
5353
rgb: "rgb(255,255,255)",
5454
rgba: "rgb(255,255,255,1)"
5555
};
56-
const { type, mode, disabled, defaultColors, color, format, invalidFormatMessage } = props;
56+
const { type, mode, disabled, defaultColors, color, format, invalidFormatMessage, onColorChange } = props;
5757
const ColorElement = getColorPicker(type);
5858
const [hidden, setHidden] = useState(mode !== "inline");
5959
const [currentColor, setCurrentColor] = useState<string | undefined>(color);
6060
const [alertMessage, setAlertMessage] = useState<string | undefined>();
6161

62-
const submitColor = (color: string): void => {
63-
setCurrentColor(color);
64-
props.onColorChange(color);
65-
};
62+
const submitColor = useCallback(
63+
(color: string): void => {
64+
setCurrentColor(color);
65+
onColorChange(color);
66+
},
67+
[onColorChange]
68+
);
6669

6770
const validateColor = (colorValue: string): void => {
6871
const message = validateColorFormat(colorValue, format);
@@ -86,7 +89,7 @@ export const ColorPicker = (props: ColorPickerProps): ReactElement => {
8689
submitColor(finalColor);
8790
}
8891
},
89-
[disabled, format]
92+
[disabled, format, submitColor]
9093
);
9194

9295
const renderInput = (): ReactElement => {

0 commit comments

Comments
 (0)