diff --git a/packages/grafana-ui/src/components/ColorPicker/ColorInput.tsx b/packages/grafana-ui/src/components/ColorPicker/ColorInput.tsx index 2a3554701c0..257f5993d1e 100644 --- a/packages/grafana-ui/src/components/ColorPicker/ColorInput.tsx +++ b/packages/grafana-ui/src/components/ColorPicker/ColorInput.tsx @@ -12,10 +12,11 @@ import { ColorPickerProps } from './ColorPickerPopover'; interface ColorInputProps extends ColorPickerProps, Omit { isClearable?: boolean; + buttonAriaLabel?: string; } const ColorInput = forwardRef( - ({ color, onChange, isClearable = false, ...inputProps }, ref) => { + ({ color, onChange, isClearable = false, onClick, onBlur, disabled, buttonAriaLabel, ...inputProps }, ref) => { const [value, setValue] = useState(color); const [previousColor, setPreviousColor] = useState(color); // eslint-disable-next-line react-hooks/exhaustive-deps @@ -44,12 +45,14 @@ const ColorInput = forwardRef( } }; - const onBlur = () => { + const onBlurInput = (event: React.FocusEvent) => { const newColor = tinycolor(value); if (!newColor.isValid()) { setValue(color); } + + onBlur?.(event); }; return ( @@ -57,8 +60,10 @@ const ColorInput = forwardRef( {...inputProps} value={value} onChange={onChangeColor} - onBlur={onBlur} - addonBefore={} + disabled={disabled} + onClick={onClick} + onBlur={onBlurInput} + addonBefore={} ref={ref} /> ); @@ -71,13 +76,20 @@ export default ColorInput; interface ColorPreviewProps { color: string; + onClick?: React.MouseEventHandler; + disabled?: boolean; + ariaLabel?: string; } -const ColorPreview = ({ color }: ColorPreviewProps) => { +const ColorPreview = ({ color, onClick, disabled, ariaLabel }: ColorPreviewProps) => { const styles = useStyles2(getColorPreviewStyles); return ( -
)} -
setIsOpen(true)}> - -
+ setIsOpen(true)} + onBlur={() => setIsOpen(false)} + ref={ref} + isClearable + />
);