To this <color-picker color="ctrl.panel.LabelColor" onChange="ctrl.render()"></color-picker>
I’m getting javascript errors in the onChange function call
react-dom.production.min.js:27 Uncaught TypeError: this.props.onChange is not a function
at t.onColorSelect (ColorPicker.tsx:13)
at t.setColor (ColorPickerPopover.tsx:37)
at t.sampleColorSelected (ColorPickerPopover.tsx:42)
at ColorPalette.tsx:36
at Object.u (react-dom.production.min.js:26)
It’s been a long time since I looked at any of this - so I may be wrong.
As far as I can tell, I never implemented the change, leaving the color-picker code as-is.
On the other hand, I found this note that seems to answer the question - apparently, the OnChange function uses function binding instead of value binding.
See here:
This should be a simple enough change - I will put thi son my to-do list for when I get around to Grafana updates again.
Update - I’ve spent a few minutes reading through the link I gave above - and it seems MUCH more complicated and unclear than I had at first thought.
Over a year has passed now, so I expect this has been resolved. Just keep digging - and please let me know what you find. I, too, will be looking into this when I have some spare time. In the meantime, I think the old spectrum-picker still works. For the time being, at least.
@mdmoore
Thank you for the reply and the link! I will have a look at it!
I am using the color-picker into other html files, and it is working great (I pass the function i want to call whenever the user chooses a color, to the ‘onChange’ property). However for some reason it is not working now in the html file i am trying to implement it.
I have realized that the function i pass (to the ‘onChange’ property) is called whenever there is a change in the panel, and not when I choose a color. For example, when i click on somewhere else than the color-picker, the function that is passed is called. But when i click on a color, the error, we described above, shows up.
If i manage to find out what is the problem, i will keep you updated. Thank you again!
After a lot of tries, i realized that there is no problem with the color picker.
I am just not passing right the function i would like to call, and as a result the function binding is not working properly.
Try passing the function without any brackets, and see if that works: