New on the web: programmatically open a native date picker (#blogPost)

Not too long ago, we finally got cross-browser-supported date input elements. With Safari joining the party, we’re now all green on the browser support front to show native date pickers everywhere.


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Not too long ago, we finally got cross-browser-supported date input elements. With Safari joining the party, we're now all green on the browser support front to show native date pickers everywhere.

MDN Compat Data (source)
Browser support info for type="date"
chrome chrome_android edge firefox firefox_android safari safari_ios samsunginternet_android webview_android
20 true 12 57 57 14.1 5 true true

There was still one piece missing, though. If now all major browsers support native date pickers, developers asked for a method to programmatically open it.

Say hello to elem.showPicker()!

const button = document.querySelector("button");
const dateInput = document.querySelector("input");
button.addEventListener("click", async () => {
  try {
    await dateInput.showPicker();
    // A date picker is shown.
  } catch (error) {
    // Use external library when this fails.
  }
});

The new method will be available in Chromium 99+.

MDN Compat Data (source)
Browser support info for dateInput.showPicker()
chrome chrome_android edge firefox firefox_android safari safari_ios samsunginternet_android webview_android
99 99 99 Nei Nope Nein 99

Webkit and Firefox also showed interest in implementing it:

I just love it when we get new DOM methods!


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2022-01-09T18:45:00+00:00) New on the web: programmatically open a native date picker (#blogPost). Retrieved from https://www.scien.cx/2022/01/09/new-on-the-web-programmatically-open-a-native-date-picker-blogpost/

MLA
" » New on the web: programmatically open a native date picker (#blogPost)." Stefan Judis | Sciencx - Sunday January 9, 2022, https://www.scien.cx/2022/01/09/new-on-the-web-programmatically-open-a-native-date-picker-blogpost/
HARVARD
Stefan Judis | Sciencx Sunday January 9, 2022 » New on the web: programmatically open a native date picker (#blogPost)., viewed ,<https://www.scien.cx/2022/01/09/new-on-the-web-programmatically-open-a-native-date-picker-blogpost/>
VANCOUVER
Stefan Judis | Sciencx - » New on the web: programmatically open a native date picker (#blogPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/09/new-on-the-web-programmatically-open-a-native-date-picker-blogpost/
CHICAGO
" » New on the web: programmatically open a native date picker (#blogPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2022/01/09/new-on-the-web-programmatically-open-a-native-date-picker-blogpost/
IEEE
" » New on the web: programmatically open a native date picker (#blogPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2022/01/09/new-on-the-web-programmatically-open-a-native-date-picker-blogpost/. [Accessed: ]
rf:citation
» New on the web: programmatically open a native date picker (#blogPost) | Stefan Judis | Sciencx | https://www.scien.cx/2022/01/09/new-on-the-web-programmatically-open-a-native-date-picker-blogpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.