-
Notifications
You must be signed in to change notification settings - Fork 56
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
HTMLInputElement showPicker() #688
Comments
I think this is a good addition, and solves real user needs |
I believe that with user activation delegation, you need to add something (like feature identifier name) to make this work for iframes etc Like here: https://github.com/w3c/webappsec-permissions-policy/blob/main/features.md |
I'm definitely familiar with the user needs this addresses (in fact, I believe I've even been on the author end of said use cases!), so it's exciting to see work in that direction. Some questions:
Doesn't this leak information about whether the user has interacted with the page, that silently doing nothing does not? |
That's one direction we could go in, but I worry that it's a bit unexpected. click() rarely has these sorts of side effects, and the fact that it does so on file and color feels like a legacy quirk instead of something we want to extend. There's also a minor compat risk that people are calling click() and expecting no-op behavior today... although I doubt it'd be that risky. I think the main argument is one I allude to in whatwg/html#3232, which is that by not tying pickers to clicks, we allow a broader possible range of browser UIs for form controls, both now and in the future. Which has always felt important to me, given how we've seen things evolve with smartphones and watches and so on.
I think we're kind of defining "all UIs we may this to trigger" to be pickers. That is, Perhaps another way of phrasing this is, are there other non-picker UIs that developers might want to show, in the same situations they want to show pickers? And would it be better for developers to not have to know the difference, but instead just trigger any such UIs? It's hard to say without examples, but I lean toward "picker" being a well-understood paradigm, and believing that it'll extend in the future to other non-pickers might be hard for developers to reason about...
No; this information is already available in plenty of ways, e.g. by using explicit event listeners for the activation triggering input events. |
Yeah, I noted that under "possible future work" in the mini-explainer:
|
Yeah, I agree I wouldn't expect that to be common. The way I see it, the advantages of
One downside is that it couples synthetic clicks with opening the picker: is there any case where authors may want to do one without the other?
If I understand your point correctly (?), you are saying that browsers in the future may want to provide more granular UIs which display different pickers depending on the location of the click, and thus a general I see that in theory, though why not add a separate API call then, if that happens? They're not mutually exclusive. Then I could be wrong, but it seems inconsistent to me to have It's also a bit unclear what a "picker" is. E.g. in an |
Such UI already exists, e.g., try Similar situation with |
One concern here is feature detection, which is already difficult and fragile for various input types. I want to be sure that developers can detect if the browser can display a picker so they have the option to adjust their UI and/or display a custom picker when needed. Otherwise we're generally happy with this and are glad to see it moving forward. |
Rejecting the if ("showPicker" in HTMLInputElement.prototype) {
try {
await document.querySelector("input").showPicker();
}
catch (error) {
if (error == "NotSupportedError") {
/* Show custom picker */
}
}
} else {
/* Show custom picker */
} |
Thanks for bringing this up; it's quite a worthwhile discussion. I think this is a tradeoff. By changing the behavior to make whether a picker was shown or not detectable, we introduce compat issues that constrain browsers from changing their UI in the future. I.e., adding or removing pickers from controls could now become a breaking change for websites. This is an area browsers have been hesitant to be constrained on, in the past. It also introduces potential interop issues. Right now, if you call showPicker(), it will never throw. But with that proposal, it might work fine in some browsers, and throw in others. This could lead to scenarios where, in the browsers you test with, there's no need for a So adding any sort of feature-detection which exposes whether a browser supports a given picker, or not, creates new interop and compat risks that the current proposal doesn't have. But, it makes the proposal more useful for the specific case where a developer definitely wants to show a picker, even if a browser doesn't support it, and thus plans to perform good feature testing and add good fallbacks for such non-supporting browsers. My instinct is to wait to gather more data on in-the-wild usage to see whether the majority of use cases are:
The current API is designed more for the former. If we find out that in the wild people are actually more interested in the latter, then we can consider adding feature detection abilities to serve that use case, and having a cross-browser discussion about whether that's worth the compat and interop risks. |
It's anecdata (and real-world data wins ofc), but I can assure you that the 'I really want a picker here (because users typing dates is extremely error-prone), and would prefer the native one, but will roll my own if I have to' situation has happened to me. There are also a lot of UI widgets out there implementing date pickers, and I expect most of them fail somewhere on a11y, i18n, and l10n, so user experience would be well served if they can use a native picker that gets it right when available. Provided that If Which brings up another thought, what about accepting an AbortSignal in showPicker()? |
To allow the web developer to dismiss a picker even if the user is interacting with it? Yeah, we mentioned
as a possible future extension in the explainer. |
A |
Yeah, I agree that's probably a better API than closePicker() in particular, if we do hear requests of that sort. |
@domenic, we had another round of discussions with TAG today and our consensus is still wanting to see detectability of the proposed feature. We want to close the review with this last issue addressed. (assuming detectability is provided) Another question I have is whether you considered exposing finer granularity of UI detectability? In the case a picker is supported, that picker can be UI implemented by the browser vs the OS native picker. This type of distinction will be just as important when component implementers are making the decision to show native vs theirs. |
Thanks for the feedback! My current position is that it's not a worthwhile tradeoff, to constrain and expose browser UI specifics in that way, but I understand we differ in that regard. |
Thank you for confirming your position @domenic. As you stated, we do differ in our opinions, and it doesn't look we can add anything else for now, thus closing the review. |
Braw mornin' TAG!
I'm requesting a TAG review of the
showPicker()
method forHTMLInputElement
.The
showPicker()
element is a new addition toHTMLInputElement
which addresses a very common request from web developers: programmatically showing a picker for controls like date etc.Further details:
We'd prefer the TAG provide feedback as (please delete all but the desired option):
💬 leave review feedback as a comment in this issue and @-notify @domenic, @beaufortfrancois, and @annevk
The text was updated successfully, but these errors were encountered: