-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Proposal: Add a way to open programmatically a date picker #6909
Comments
Should this also come along with an |
Should this explicitly only work for these inputs? Other inputs which have pickers in some browsers are |
Also (The other thing I was thinking about, which is somewhat off-topic, is that you might want to display the picker exclusively as some sites do (i.e., without the input box), but perhaps that's best left to libraries as there's often additional requirements.) |
I'm not sure. According to the spec, a dialog element without an open attribute specified should not be shown to the user. Shall we then have an "open" attribute for |
FYI There's a JS API already for Contact picker Currently Having |
We'd have to find out if that's something developers need. |
In Chrome I agree those do not have pickers. In other browsers they do. (In some cases historical browsers like Opera.) |
Not supported in Firefox or Safari though. And we could still have a more general method even with an existing method for a specific case. |
I was given an action item to see what
❗ means the picker does open, on both programmatic * means the picker does not open via programmatic Blank means neither clicking on the label nor programmatic E.g. on mobile Chrome, the user clicking on the label text for None of the elements in "Not very likely to have a picker, but could conceivably", besides sometimes besides Thankfully nobody showed pickers on I can't think of anything unifying these. E.g. you might think Chrome's approach is "display fullscreen pickers, don't display anchored pickers", but Here's my proposal:
We could also contemplate not special-casing |
Thank you @domenic for the thorough investigation. Here are my results on Safari Mobile. Feel free to edit your post earlier.
|
Thanks @beaufortfrancois! You inspired me to borrow my girlfriend's iPhone and do some of my own testing on the |
New test page with no user activation: https://boom-bath.glitch.me/pickers-2.html Results:
Conclusion: we can definitely impose a user-activation restriction on both the activation behavior and the new |
New test page where the pickers are in a cross-origin iframe: https://creative-abrupt-bladder.glitch.me/ Results: on desktop Firefox and desktop Chrome, at least, there is no difference in behavior from the first-party case. I.e. you can open file and color pickers with a user-activation click. Conclusion: it would be a web compat lift to lock down cross-origin iframe color and file pickers. So although that's a good idea, I think we should pursue it as a separate issue, since I suspect it'd cause a lot of web developer pain (e.g. third-party file picker widgets). We could make the new |
I like the idea of restricting the new capability where it makes sense to do so. |
@domenic Is there anything I can do to help moving this forward? |
@beaufortfrancois I'll work on the spec soon, but a few things could help from the implementation side:
|
If the HTML input element is already in the DOM, it makes sense to open where the element is. However if the element is not in the DOM already, |
Interesting! Let me test what all browsers do in that case. |
This CL adds an experimental method to the HTMLInputElement interface to allow web developers to show the browser picker for temporal, color, and file input elements. It requires a user gesture and is disallowed for cross-origin iframes except for file and color input elements for now. Intent to prototype: TODO Test: https://show-picker.glitch.me/ Spec: whatwg/html#6909 Bug: 939561 Change-Id: Icd59429c069ce5c70903f708f5d6da41a16ba90f
Here's the WIP Chromium CL for the new |
In the process of prototyping @beaufortfrancois pointed out that Although IMO treating
Happy to discuss more here or in the triage call. In particular it'd be interesting to hear peoples thoughts between: do |
open() sounds a bit odd for a method on an input element. It isn't immediately clear to the reader what it would do. (and since EyeDropper API is just a proposal, it could be changed to have showPicker?) |
I guess it could go the other way, yeah - I also don't have strong feelings on naming, but consistency would be nice since both of these are new. |
On a file input I could see people thinking |
For an "empty" |
I don't feel strongly either about the naming of this method and I agree some consistency would be great as well for web developers. FYI I've left a comment at WICG/eyedropper-api#18 (comment) to let EyeDropper folks know about this issue. |
…ent interface, a=testonly Automatic update from web-platform-tests Add showPicker() method to HTMLInputElement interface This CL adds an experimental method to the HTMLInputElement interface to allow web developers to show the browser picker for temporal, color, and file input elements. It requires a user gesture and is disallowed for cross-origin iframes except for file and color input elements for now. Intent to prototype: https://groups.google.com/a/chromium.org/g/blink-dev/c/fEebe5uXQ1I/m/ox6SBEQ5AAAJ Test: https://show-picker.glitch.me/ Spec: whatwg/html#6909 Bug: 939561 Change-Id: Icd59429c069ce5c70903f708f5d6da41a16ba90f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056920 Commit-Queue: François Beaufort <beaufort.francois@gmail.com> Reviewed-by: Mason Freed <masonf@chromium.org> Cr-Commit-Position: refs/heads/main@{#937999} -- wpt-commits: a3e1b754ba20cd38fcbc40d0b69271178675ee01 wpt-pr: 31484
…ent interface, a=testonly Automatic update from web-platform-tests Add showPicker() method to HTMLInputElement interface This CL adds an experimental method to the HTMLInputElement interface to allow web developers to show the browser picker for temporal, color, and file input elements. It requires a user gesture and is disallowed for cross-origin iframes except for file and color input elements for now. Intent to prototype: https://groups.google.com/a/chromium.org/g/blink-dev/c/fEebe5uXQ1I/m/ox6SBEQ5AAAJ Test: https://show-picker.glitch.me/ Spec: whatwg/html#6909 Bug: 939561 Change-Id: Icd59429c069ce5c70903f708f5d6da41a16ba90f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056920 Commit-Queue: François Beaufort <beaufort.francois@gmail.com> Reviewed-by: Mason Freed <masonf@chromium.org> Cr-Commit-Position: refs/heads/main@{#937999} -- wpt-commits: a3e1b754ba20cd38fcbc40d0b69271178675ee01 wpt-pr: 31484
Developers have also been asking for the ability to open suggestions for
|
That's a great point. I forgot to test those. IMO |
I have a WIP Chromium CL at https://chromium-review.googlesource.com/c/chromium/src/+/3284804 to open those pickers. Good catch @mnoorenberghe! |
This CL adds an experimental method to the HTMLInputElement interface to allow web developers to show the browser picker for temporal, color, and file input elements. It requires a user gesture and is disallowed for cross-origin iframes except for file and color input elements for now. Intent to prototype: https://groups.google.com/a/chromium.org/g/blink-dev/c/fEebe5uXQ1I/m/ox6SBEQ5AAAJ Test: https://show-picker.glitch.me/ Spec: whatwg/html#6909 Bug: 939561 Change-Id: Icd59429c069ce5c70903f708f5d6da41a16ba90f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056920 Commit-Queue: François Beaufort <beaufort.francois@gmail.com> Reviewed-by: Mason Freed <masonf@chromium.org> Cr-Commit-Position: refs/heads/main@{#937999}
@mnoorenberghe https://chromiumdash.appspot.com/commit/92e5fe8556d41ba34766129574df624ea2413ffa has landed. Give https://show-picker.glitch.me/ a try in Chrome Canary 98 98.0.4726.0. You'll need to enable the experimental web platform features flag for this. |
FYI I've just sent an intent to ship at blink-dev: https://groups.google.com/a/chromium.org/g/blink-dev/c/YfnM0ubs53k |
https://bugs.webkit.org/show_bug.cgi?id=237192 LayoutTests/imported/w3c: Reviewed by Darin Adler. Update test expectations as more tests are now passing. * web-platform-tests/html/dom/idlharness.https-expected.txt: * web-platform-tests/html/semantics/forms/the-input-element/show-picker-cross-origin-iframe-expected.txt: * web-platform-tests/html/semantics/forms/the-input-element/show-picker-expected.txt: Source/WebCore: Reviewed by Darin Adler. At whatwg/html#6909, it proposes to add a new HTMLInputElement::showPicker() method to show a brower picker for temporal, color and file input elements. Chromium has introduced this feature at https://bugs.chromium.org/p/chromium/issues/detail?id=939561. This CL imports the changes from Chromium CLs at https://chromium-review.googlesource.com/c/chromium/src/+/3056920 and https://chromium-review.googlesource.com/c/chromium/src/+/3310677 The support for temporal input element is not included in this CL. We might need a bit more investigation on it and hopefully will addess at a later stage. * html/ColorInputType.cpp: (WebCore::ColorInputType::handleDOMActivateEvent): (WebCore::ColorInputType::showPicker): (WebCore::ColorInputType::allowsShowPickerAcrossFrames): * html/ColorInputType.h: * html/FileInputType.cpp: (WebCore::FileInputType::handleDOMActivateEvent): (WebCore::FileInputType::showPicker): (WebCore::FileInputType::allowsShowPickerAcrossFrames): * html/FileInputType.h: * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::showPicker): * html/HTMLInputElement.h: * html/HTMLInputElement.idl: * html/InputType.cpp: (WebCore::InputType::allowsShowPickerAcrossFrames): (WebCore::InputType::showPicker): * html/InputType.h: LayoutTests: Reviewed by Darin Adler . * platform/gtk/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/ios-wk2/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/mac-wk1/imported/w3c/web-platform-tests/html/dom/idlharness.https-expected.txt: * platform/mac-wk1/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/show-picker-cross-origin-iframe-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/show-picker-cross-origin-iframe-expected.txt. Canonical link: https://commits.webkit.org/248774@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291742 268f45cc-cd09-0410-ab3c-d52691b4dbfc
@domenic @beaufortfrancois Any chance to help with clarifying the question at https://bugs.webkit.org/show_bug.cgi?id=237192#c19? This WebKit patch is an import of the Chromium showpicker() CL. Thanks. |
As you can see below, in Chromium void HTMLInputElement::showPicker(ExceptionState& exception_state) {
LocalFrame* frame = GetDocument().GetFrame();
if (type() != input_type_names::kFile && type() != input_type_names::kColor &&
frame) {
const SecurityOrigin* security_origin =
frame->GetSecurityContext()->GetSecurityOrigin();
const SecurityOrigin* top_security_origin =
frame->Tree().Top().GetSecurityContext()->GetSecurityOrigin();
if (!security_origin->IsSameOriginWith(top_security_origin)) {
exception_state.ThrowSecurityError(
"HTMLInputElement::showPicker() called from cross-origin iframe.");
return;
}
}
if (!LocalFrame::HasTransientUserActivation(frame)) {
exception_state.ThrowDOMException(
DOMExceptionCode::kNotAllowedError,
"HTMLInputElement::showPicker() requires a user gesture.");
return;
}
input_type_view_->OpenPopupView();
} |
Thanks @beaufortfrancois for your prompt response. Yes, this is what we have in WebKit imported code as well. What we are trying to clarify here is, we check on cross-frame and user gesture status and throw exceptions if either of those applies. What is neither applies, silently do nothing? As per #6909 (comment), it mentioned that "It should not consume user activation.". Does it mean that silently doing nothing is intentional? |
That is my understanding according to https://html.spec.whatwg.org/multipage/input.html#dom-input-showpicker
Let's wait on @domenic answer as well. |
Yes, that is correct. |
Thanks both. Just to confirm - If not applicable, do nothing? |
Yes, if you read the algorithm for "show the picker, if applicable", step 4 says
|
Perfect. Thanks very much! |
Also specifies that both color and file inputs show pickers on both programmatic and user clicks, since that is true in all browsers. (Previously the spec included this behavior only for file inputs.) Closes whatwg#6909. Closes whatwg#3232.
This CL adds an experimental method to the HTMLInputElement interface to allow web developers to show the browser picker for temporal, color, and file input elements. It requires a user gesture and is disallowed for cross-origin iframes except for file and color input elements for now. Intent to prototype: https://groups.google.com/a/chromium.org/g/blink-dev/c/fEebe5uXQ1I/m/ox6SBEQ5AAAJ Test: https://show-picker.glitch.me/ Spec: whatwg/html#6909 Bug: 939561 Change-Id: Icd59429c069ce5c70903f708f5d6da41a16ba90f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056920 Commit-Queue: François Beaufort <beaufort.francois@gmail.com> Reviewed-by: Mason Freed <masonf@chromium.org> Cr-Commit-Position: refs/heads/main@{#937999} NOKEYCHECK=True GitOrigin-RevId: 20c51940a27d0ca85bac08d5c0a745812e6a0ca2
This CL makes sure the showPicker() method actually shows the picker on Android. It wasn't the case with the previous CL[1] because MultipleFieldsTemporalInputTypeView is only supported on Desktop. ChooserOnlyTemporalInputTypeView is the class to update to add support for showPicker() on Android. [1] https://chromium-review.googlesource.com/c/chromium/src/+/3056920 Change-Id: Ibab81e7d54c6c8e5442aef1d60f4b1cde3dba2c6 Test: https://show-picker.glitch.me/ Spec: whatwg/html#6909 Bug: 939561 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3263866 Commit-Queue: François Beaufort <beaufort.francois@gmail.com> Reviewed-by: Mason Freed <masonf@chromium.org> Cr-Commit-Position: refs/heads/main@{#938980} NOKEYCHECK=True GitOrigin-RevId: 43f41a8d8039ce72ca983f5892c4484e16d364d1
Background:
Developers have been asking for years for a way to programmatically open a browser date picker. See https://www.google.com/search?q=programmatically+open+date+picker+site:stackoverflow.com
Because of that, they had to rely on custom widget libraries and CSS hacks for specific browsers.
Date pickers in Chrome Desktop, Chrome Mobile, Safari Desktop, Safari Mobile, and Firefox Desktop (July 2021).
Proposal
A new
showPicker()
method to theHTMLInputElement
interface would show a browser picker (if supported) for<input type="date">
,<input type="month">
,<input type="week">
,<input type="datetime-local">
, and<input type="time">
HTML elements . This method is handy, easy to use, and friendly to discover.As it's already possible to listen to
change
events to know when the HTML element value changes, I believe it's OK to make this method synchronous.Example usage
Feature detection
Open questions
Alternative considered
Adding a brand new
DatePicker
object that could be used with HTML elements or in standalone mode seems overkill.According to Should <input type=date> have a "input activation behavior" defined? #3232 (comment), it seems like a synthetic
click()
should not trigger a browser date picker.Resources
The text was updated successfully, but these errors were encountered: