diff --git a/packages/scene-composer/src/components/panels/scene-components/tag-style/ColorPicker/ColorPicker.spec.tsx b/packages/scene-composer/src/components/panels/scene-components/tag-style/ColorPicker/ColorPicker.spec.tsx index 2be5c34b2..263246adc 100644 --- a/packages/scene-composer/src/components/panels/scene-components/tag-style/ColorPicker/ColorPicker.spec.tsx +++ b/packages/scene-composer/src/components/panels/scene-components/tag-style/ColorPicker/ColorPicker.spec.tsx @@ -15,7 +15,7 @@ describe('ColorPicker', () => { it('calls onSelectColor when color is selected', () => { const onSelectColorMock = jest.fn(); - render(); + render(); const colorElement = screen.getByTestId('color-preview'); fireEvent.click(colorElement); fireEvent.click(screen.getAllByTitle('#000000')[0]); @@ -24,7 +24,9 @@ describe('ColorPicker', () => { it('calls handleHexCodeChange when hex code is entered', async () => { const onSelectColorMock1 = jest.fn(); - const { container } = render(); + const { container } = render( + , + ); const polarisWrapper = wrapper(container); const input = polarisWrapper.findInput(); expect(input).toBeDefined(); diff --git a/packages/scene-composer/src/components/panels/scene-components/tag-style/ColorPicker/ColorPicker.tsx b/packages/scene-composer/src/components/panels/scene-components/tag-style/ColorPicker/ColorPicker.tsx index eb4008dd6..a8adcdeff 100644 --- a/packages/scene-composer/src/components/panels/scene-components/tag-style/ColorPicker/ColorPicker.tsx +++ b/packages/scene-composer/src/components/panels/scene-components/tag-style/ColorPicker/ColorPicker.tsx @@ -24,14 +24,15 @@ export const ColorPicker = ({ onUpdateCustomColors, colorPickerLabel, customColorLabel, -}: IColorPickerProps): JSX.Element => { +}: IColorPickerProps) => { const [showPicker, setShowPicker] = useState(false); const [newColor, setNewColor] = useState(color); const [showChromePicker, setShowChromePicker] = useState(false); const [hexCodeError, setHexCodeError] = useState(''); // State variable for hex code error const [customInternalColors, setCustomInternalColors] = useState(customColors ?? []); + const generateRandomString = Math.random().toString(16).slice(2); + const [randomDomId] = useState(generateRandomString); const intl = useIntl(); - /** * This method uses a regular expression (`hexRegex`) to validate a hex color code. * The regex checks if the hex code starts with a "#" symbol, followed by either a @@ -47,7 +48,11 @@ export const ColorPicker = ({ const handleOutsideClick = useCallback((event: MouseEvent) => { const target = event.target as HTMLElement; - const pickerContainer = document.getElementById('circle-picker'); + const buttonsvg = document.getElementById('button-svg' + `${randomDomId}`); + if (buttonsvg && buttonsvg.contains(target)) { + return; // We have a different handler for button click + } + const pickerContainer = document.getElementById('circle-picker' + `${randomDomId}`); if (pickerContainer && !pickerContainer.contains(target)) { setShowPicker(false); } @@ -59,7 +64,6 @@ export const ColorPicker = ({ } else { document.removeEventListener('click', handleOutsideClick); } - return () => { document.removeEventListener('click', handleOutsideClick); }; @@ -72,10 +76,6 @@ export const ColorPicker = ({ } }; - const handleClick = () => { - setShowPicker(!showPicker); - }; - const handleShowChromePicker = () => { setShowChromePicker(true); setShowPicker(false); @@ -138,12 +138,13 @@ export const ColorPicker = ({ {colorPickerLabel} } onClick={() => { - handleClick(); + setShowPicker(!showPicker); setHexCodeError(''); }} /> @@ -153,7 +154,7 @@ export const ColorPicker = ({ value={newColor} onChange={handleHexCodeChange} /> - + {showPicker && !showChromePicker && ( @@ -167,11 +168,11 @@ export const ColorPicker = ({ onChange={handleColorChange} /> - - - - {customColorLabel} - + + + {customColorLabel} + +