I am using colour picker in my project using input <type = "colour">. While using Chrome everything works fine, Colour picker can be closed by clicking on any part of the browser and also when i refresh or close the current tab. However, in case of firefox browser there is a very specific close button to close the colour picker and when i refresh or close the current tab the colour picker still remains there unless i close it using the respective button.
I came across a solution mentioned in How to close an html5 color picker? but the following solution is not effective for firefox either:
var input = document.getElementById('my-color');
// when you click the color picker, we'll run our code to close it after 2 seconds.
input.addEventListener('focus', function() {
setTimeout(()=>{
// toggle the type attribute to close the picker!
input.setAttribute('type','text');
input.setAttribute('type','color');
}, 2000);
});
<input type="color" value="#ffaacc" id="my-color"/> <- Click me
How can i replicate the chrome behaviour for firefox as well?