I am trying to make a custom datepicker using input[type='date']
and something that ressembles the code below :
#dpk{
display: none;
}
label{
border: 1px solid black;
padding: .2em .3em;
cursor: pointer;
}
<div class='input'>
<label for="dpk">Chose a date</label>
<input type='date' id='dpk'/>
</div>
For all types of input, clicking on a label (if the 'for' attribute is setup correctly) will trigger automatically a click on the input. We can use this technique to make a custom input[type='file']
as explained by this answer and this jsfiddle.
The output that I expected for the date input was that clicking on the label would show the date picker and it works fine on Firefox but doesn't do anything in Chrome and Edge. And the code snippet above will show a date picker when you click on the text if you use Firefox but won't show anything if you're on Edge or Chrome.
This is what I think causes the problem : In Firefox, a date input looks like this
but in Chrome and Edge they look like this
In Firefox, clicking on any area of the input will trigger the datepicker to show (while the user can also type the date manually) but in the two others one must click on the calendar icon since clicking elsewhere would just let us edit the date just as a text input.
So my question is : is there a way to make this work with JavaScript (or in HTML and CSS)?
document.querySelector('input[type="date"').click()
won't work here for the reason I explained above.
Thanks in advance.