Search code examples
javascripthtmlioscolor-picker

Open input color programatically in IOS


I noticed that in IOS I can't open the color picker of the default brower input programmatically. It works on desktop versions, and on other mobiles. Does anyone knows how I can fix the issue in IOS (Ipad, Iphones) ?

The following code reproduce the issue :

function onClick() {
    document.getElementById('picker').click();
}
<button onclick="onClick()">
  Open Color Picker
</button>

<br>

<input type="color" id="picker">


Solution

  • I found a workaround for the issue. I'm using a label linked to the input, and I trigger the label's click instead of the input one.

    function onClick() {
        document.getElementById('label').click();
    }
    <button onclick="onClick()">
      Open Color Picker
    </button>
    
    <label id="label" for="picker"></label>
    
    <br>
    
    <input type="color" id="picker">