-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date picker access in contenteditable elements #8335
Comments
This comment was marked as spam.
This comment was marked as spam.
This might be what cc @lukewarlow |
See also openui/open-ui#922 |
There's an awkward workaround with showPicker which requires DOM manipulation: <!DOCTYPE html>
<meta charset="utf-8" />
<div contenteditable id="target">foo</div>
<script>
// Open date picker when pressing number keys at the current cursor
// And insert the date when picked
target.onkeydown = (ev) => {
if (!isNaN(parseInt(ev.key))) {
ev.preventDefault();
const input = document.createElement("input");
input.type = "date";
input.style = "width: 0px; height: 0px; visibility: hidden";
const range = getSelection().getRangeAt(0);
range.insertNode(input);
input.showPicker();
input.onchange = () => {
input.remove();
range.insertNode(new Text(input.value));
};
input.oncancel = () => input.remove();
}
};
</script> Edit: |
That only fires for file inputs. |
Oh right, thanks. Do we know it's missed somehow or is it intentional to not fire it for other pickers? |
Currently the idea is that pickers shouldn't be observable because not all browsers use them for every input on every computer (desktop Vs mobile) so they don't want authors relying on that. |
The datepicker API is currently only accessible via the HTMLInputElement. In some cases, developers need to use the contenteditable attribute to allow user input for alternative element types such as the HTMLDivElement, however datepicker is unfortunately not accessible to them.
The ability for developers to access a cross-platform capable, unified design date picker without having to download a third-party library is extremely powerful. I utmost understand that such a feat does not come without having to deal with 100s of different use-cases and the issues that come with each one, but I wanted to ask if facilitating the access of its API for the contenteditable elements was anywhere on your roadmap as this is an issue that I am facing upfront and I believe other devs will run into this use-case in the future as well.
The text was updated successfully, but these errors were encountered: