Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Color Input "oninput" event behaving differently on Chrome on Windows

On firefox, the oninput event of a color type input is fired while the OS color picker window is opened, everytime the user switches a color.

Now, on chrome it works exactly as the onchange event, it only fires if the actual color changes after pressing ok on the color picker window.

Is there a way to get the expected behavior on chrome? Is this a bug or a implementation choice?

Also, is there an event that fires even if the user doesn't change the color but only opens the color picker and presses ok? A onclick wouldn't be ideal as that would also trigger if the user presses cancel.

const colorInput = document.getElementById('color');
color.oninput = evt => {
  console.log('oninput');
}
<input id="color" type="color">

Edit : It seems that chrome and edge behave the same.

like image 312
Mojimi Avatar asked Nov 06 '22 19:11

Mojimi


1 Answers

Unfortunately, this is a Windows limitation. The ChooseColor function is responsible for that dialog and it only outputs the color information when the user closes the dialog.

If you want the user to be able to change colors live, consider using a library like jscolor.

like image 101
D. Pardal Avatar answered Nov 14 '22 22:11

D. Pardal