Skip to content
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

Add showPicker to <select> elements #9754

Merged
merged 9 commits into from
Nov 16, 2023
Merged

Conversation

lukewarlow
Copy link
Member

@lukewarlow lukewarlow commented Sep 19, 2023

Closes #7957 and #9757

Mini-explainer for TAG review / blink-dev purposes:

The showPicker() method is a new addition to HTMLSelectElement which addresses a common request from web developers: programmatically showing the option picker UI for a select element

<select id="select">
  <option>Item 1</option>
  <option>Item 2</option>
</select>
<button onclick="select.showPicker()">Show the select option picker</button>

In today's browsers there's currently no way to programatically open a select element. This spec adds a new method to a select element to make that possible, following in the footsteps of the showPicker() method added to HTMLInputElement.

showPicker() is specified with a few restrictions to improve security:

It can only be called with transient user activation. If called without, it will throw a "NotAllowedError" DOMException. (This is the same as how it behaves on inputs.)

It can only be called in same-origin iframes. If called in a cross-origin iframe, it will throw a "SecurityError" DOMException.

(See WHATWG Working Mode: Changes for more details.)


/acknowledgements.html ( diff )
/form-elements.html ( diff )
/input.html ( diff )

@lukewarlow
Copy link
Member Author

I'm happy to implement this in Chromium as an external contributor. Idk if that counts me as 1 implementor for the purposes of the WhatWG?

Once it's deemed this PR is wanted I'll happily go and file the necessary bugs and write any web platform tests needed.

@sideshowbarker
Copy link
Contributor

s/showPicker() element/showPicker() method/

…in the first sentence of the issue description

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Chromium is willing to ship it enabled by default that would count as implementer interest.

source Outdated Show resolved Hide resolved
@annevk
Copy link
Member

annevk commented Sep 19, 2023

In principle WebKit is supportive of this change, but we'd like some clarity on #9757.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 20, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 20, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
@lukewarlow
Copy link
Member Author

@emilio do you or any other gecko folks have any thoughts on this?

@emilio
Copy link
Contributor

emilio commented Sep 21, 2023

At a glance it seems fine. CC @evilpie who implemented showPicker(). Can you file a mozilla standards position issue? That's the way of getting a more official position :)

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 29, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 29, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 29, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 29, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 29, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
aarongable pushed a commit to chromium/chromium that referenced this pull request Sep 30, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4875550
Commit-Queue: Luke <lukewarlow156@gmail.com>
Reviewed-by: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1203564}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 30, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4875550
Commit-Queue: Luke <lukewarlow156@gmail.com>
Reviewed-by: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1203564}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 30, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4875550
Commit-Queue: Luke <lukewarlow156@gmail.com>
Reviewed-by: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1203564}
@lukewarlow
Copy link
Member Author

Have made draft MDN PRs for this feature. All that's left is a resolution to #9757 for WebKit and I think this should be good to go?

@lukewarlow
Copy link
Member Author

Anything else I can do to nudge this across the finish line?

@lukewarlow
Copy link
Member Author

https://groups.google.com/a/mozilla.org/g/dev-platform/c/S9cdPUJSyL8/m/c8FUILXXAwAJ - Firefox Intent to Ship (unflagged on main)
https://groups.google.com/a/chromium.org/g/blink-dev/c/qew_ILTXWSY/m/AxHrcWzuAQAJ - Chrome Intent to Ship (flagged on main waiting for this PR to merge before unflagging)
WebKit has a partial (desktop only) implementation (flagged), needs iOS work which I plan to do and then it should be ready to go through the launch steps.

cc @annevk @domenic to give this a nudge

@annevk
Copy link
Member

annevk commented Oct 31, 2023

Hey @lukewarlow, I'm sorry, but I'm still a little stuck on #9757 (comment). I realize this is not adding anything new compared to what's already out there, but it seems problematic to me that the existing API is so wildly different across implementations for the disconnected case (when the element is not in the document tree). And also, that for the disconnected case which is reportedly a key use case there's essentially no way to position the widget. That seems like a rather big design flaw to me with the original feature that needs addressing first.

@lukewarlow
Copy link
Member Author

I'm not actually convinced that (out of dom input) would be the majority use case? Given it basically doesn't work, and I can't think how it would without representing the pickers with pseudo elements that can take positioning data and using web tech (which wouldn't be desirable for WebKit I imagine?). That also would go counter to not wishing to expose whether a picker is implemented.

Not really sure what the next steps here are?

@lukewarlow
Copy link
Member Author

lukewarlow commented Oct 31, 2023

If authors want the pickers without the input UI that suggests to me that this is entirely the wrong path to go down and we really should be asking OpenUI to investigate exposing the pickers themselves as usable (stylable) elements?

Again not sure what WebKit would think of that as they are keen on native looking elements?

Have opened openui/open-ui#922 to start this discussion to see if open ui are interested etc

@lukewarlow
Copy link
Member Author

#9912 - uses the algorithm defined in here so I've copied this change across removing the IDL additions. This will need rebasing if that gets merged first.

@zcorpan
Copy link
Member

zcorpan commented Nov 6, 2023

I think it makes sense to require that the select element be rendered for showPicker() to work. It can be extended later if we figure out how it should work in different browsers and devices.

@lukewarlow
Copy link
Member Author

@zcorpan do you envisage any wording changes to the spec?

@zcorpan
Copy link
Member

zcorpan commented Nov 6, 2023

In the showPicker() steps, just before calling "Show the picker, if applicable":

If this is a select element or an input element whose type attribute is not in the File Upload state, and this is not being rendered, then throw a "NotSupportedError" DOMException.

@lukewarlow
Copy link
Member Author

lukewarlow commented Nov 6, 2023

Chromium currently supports showing picker for more than the file type (when not rendered). Should I just do the if this is select bit and ignore input entirely for now?

@lukewarlow
Copy link
Member Author

I've added that line but only with reference to select due to the comment above. @annevk would that be enough to alleviate concerns? If not is there anything else I can do to help move things forwards :)

@annevk
Copy link
Member

annevk commented Nov 7, 2023

That seems reasonable to me. @domenic thoughts?

@zcorpan
Copy link
Member

zcorpan commented Nov 7, 2023

OK. It seems the picker is rendered in the top-left corner for hidden non-file input types in chromium.

I suggested NotSupportedError, but maybe NotAllowedError is also appropriate.

@lukewarlow
Copy link
Member Author

I suggested NotSupportedError, but maybe NotAllowedError is also appropriate.

Apologies I missed that. Will fix that now.

@domenic
Copy link
Member

domenic commented Nov 8, 2023

@domenic thoughts?

I continue to think that a major use case for these will be showing the mobile full-screen pickers, which don't need a visible element to anchor to. I think that's how showPicker() is often used today on, e.g., date pickers.

However, I recognize that we haven't done good work on that front. We've made it too easy to create a good experience on mobile (e.g. a full-screen date picker) and a bad experience on desktop (e.g. no date picker in Firefox/Safari, or a date picker anchored to the top-left of the screen in Chrome).

So, taking a different route for select, where it just isn't possible to create a good experience on either mobile or desktop, seems like a reasonable first step. I hope we can do some work to allow all controls to work well on all platforms at some point though.

data-x="dom-input-showPicker">showPicker()</code></dfn> method steps are:</p>
data-x="dom-input-showPicker">input.showPicker()</code></dfn> and
<dfn method for="HTMLSelectElement"><code
data-x="dom-select-showPicker">select.showPicker()</code></dfn> method steps are:</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the syntax we've been using here, when we need to disambiguate between different base classes, is "The HTMLInputElement showPicker() method steps and the HTMLSelectElement showPicker() method steps".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this is addressed properly let me know if I've misunderstood.

source Show resolved Hide resolved
@annevk
Copy link
Member

annevk commented Nov 8, 2023

(Note that on iOS a select box dropdown is not fullscreen either. It used to be displayed in the keyboard area, but these days it is inline similar to desktop. So you would need some kind of coordinate system for some mobile platforms as well.)

@lukewarlow
Copy link
Member Author

Is this likely to be merged before the 17th? Just so I can update the chrome I2S accordingly.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@domenic final thoughts?

@annevk annevk merged commit e60fc35 into whatwg:main Nov 16, 2023
2 checks passed
@annevk
Copy link
Member

annevk commented Nov 16, 2023

Thanks @lukewarlow for adding this feature to HTML!

Lightning00Blade pushed a commit to Lightning00Blade/wpt that referenced this pull request Dec 11, 2023
This CL adds an experimental method to the HTMLSelectElement interface
to allow web developers to show the browser picker for select elements.
It requires a user gesture and is disallowed for cross-origin iframes.

Intent to prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/6MUAqY2r3Hg

Demo: https://select-show-picker.glitch.me/
Spec: whatwg/html#9754
Bug: 1485010
Change-Id: I822bff7b313dfa840b2a72edb66fcb4a2c7cb58d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4875550
Commit-Queue: Luke <lukewarlow156@gmail.com>
Reviewed-by: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1203564}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Automatically open option list in a <select> (HTMLSelectElement)
8 participants