-
Notifications
You must be signed in to change notification settings - Fork 66
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
Handling of focus inside a portal #257
Comments
I think worse than styling would be a flashing input cursor since that implies the page is waiting for input. Keyboard coming up would be a concern but I believe that's gated on user activation so shouldn't be an issue; though I don't know that all browsers gate on that. |
Some more details about the current implementation:
|
We don't have to show a cursor on everything that's focused, though. See below. In general my leaning would be toward treating portals the same as other top-level BCs (e.g., window.open()ed tabs, which can have their own independent focused area). It appears we already have handling to not style or show the cursor for such browsing contexts, despite them having independently changing focused area. See the example at https://jsbin.com/luyejohodu/edit?html,output . So if the only downside is styling/cursor related, then that model makes sense to me. WDYT? |
So I fiddled around some more with chrome's focus implementation, and observed a few things:
I'm not sure any of this is speced anywhere (or maybe it is and I misinterpreted the current spec); but if we treated a portal like a window without focus, we would update the activeElement every time we call |
Some of this is getting specced in whatwg/html#6172, coincidentally. |
This seems perfect to me. |
Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404
Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404
Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404
Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566072 Commit-Queue: Adithya Srinivasan <[email protected]> Reviewed-by: Lucas Gadani <[email protected]> Reviewed-by: Jeremy Roman <[email protected]> Reviewed-by: Alex Moshchuk <[email protected]> Reviewed-by: David Trainor <[email protected]> Cr-Commit-Position: refs/heads/master@{#853647}
Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566072 Commit-Queue: Adithya Srinivasan <[email protected]> Reviewed-by: Lucas Gadani <[email protected]> Reviewed-by: Jeremy Roman <[email protected]> Reviewed-by: Alex Moshchuk <[email protected]> Reviewed-by: David Trainor <[email protected]> Cr-Commit-Position: refs/heads/master@{#853647}
…ange active element, a=testonly Automatic update from web-platform-tests Portals: focus() inside portal should change active element Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566072 Commit-Queue: Adithya Srinivasan <[email protected]> Reviewed-by: Lucas Gadani <[email protected]> Reviewed-by: Jeremy Roman <[email protected]> Reviewed-by: Alex Moshchuk <[email protected]> Reviewed-by: David Trainor <[email protected]> Cr-Commit-Position: refs/heads/master@{#853647} -- wpt-commits: a507854e826d126010758ba44847d1b67fb29c01 wpt-pr: 27461
…ange active element, a=testonly Automatic update from web-platform-tests Portals: focus() inside portal should change active element Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566072 Commit-Queue: Adithya Srinivasan <adithyaschromium.org> Reviewed-by: Lucas Gadani <lfgchromium.org> Reviewed-by: Jeremy Roman <jbromanchromium.org> Reviewed-by: Alex Moshchuk <alexmoschromium.org> Reviewed-by: David Trainor <dtrainorchromium.org> Cr-Commit-Position: refs/heads/master{#853647} -- wpt-commits: a507854e826d126010758ba44847d1b67fb29c01 wpt-pr: 27461 UltraBlame original commit: 7e6160586f3c29315b5b2267b293ecbdfefd4324
…ange active element, a=testonly Automatic update from web-platform-tests Portals: focus() inside portal should change active element Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566072 Commit-Queue: Adithya Srinivasan <adithyaschromium.org> Reviewed-by: Lucas Gadani <lfgchromium.org> Reviewed-by: Jeremy Roman <jbromanchromium.org> Reviewed-by: Alex Moshchuk <alexmoschromium.org> Reviewed-by: David Trainor <dtrainorchromium.org> Cr-Commit-Position: refs/heads/master{#853647} -- wpt-commits: a507854e826d126010758ba44847d1b67fb29c01 wpt-pr: 27461 UltraBlame original commit: 7e6160586f3c29315b5b2267b293ecbdfefd4324
…ange active element, a=testonly Automatic update from web-platform-tests Portals: focus() inside portal should change active element Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566072 Commit-Queue: Adithya Srinivasan <adithyaschromium.org> Reviewed-by: Lucas Gadani <lfgchromium.org> Reviewed-by: Jeremy Roman <jbromanchromium.org> Reviewed-by: Alex Moshchuk <alexmoschromium.org> Reviewed-by: David Trainor <dtrainorchromium.org> Cr-Commit-Position: refs/heads/master{#853647} -- wpt-commits: a507854e826d126010758ba44847d1b67fb29c01 wpt-pr: 27461 UltraBlame original commit: 7e6160586f3c29315b5b2267b293ecbdfefd4324
Allows a portal document's activeElement to update when focus is called. Note that focus events won't be dispatched as the portal doesn't get page focus, and the portal WebContents isn't set as the focused WebContents (with the exception of orphaned portals). Updating the activeElement also means an autofocused element inside a portal will receive focus when the portal is activated. More discussion here: WICG/portals#257 Change-Id: If67be1f424114653983b473a80c515337d49596a Bug: 1059404 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566072 Commit-Queue: Adithya Srinivasan <[email protected]> Reviewed-by: Lucas Gadani <[email protected]> Reviewed-by: Jeremy Roman <[email protected]> Reviewed-by: Alex Moshchuk <[email protected]> Reviewed-by: David Trainor <[email protected]> Cr-Commit-Position: refs/heads/master@{#853647} GitOrigin-RevId: 11c3d6ba0f0c5e26aec2c764f9f95d037c23fc10
@a4sriniv and I were having a discussion in a separate doc about autofocus, which revealed that we probably should discuss focus in general.
My impression was that, like other top-level browsing contexts, portal browsing contexts would have an independent currently focused area (~
document.activeElement
). So e.g. code inside the portal could useautofocus=""
,element.focus()
, etc., without impacting the embedder browsing context at all.focus
andblur
events would fire inside the portal browsing context, completely independent from the embedder browsing context. And, this currently focused area could be styled differently, e.g. matching:focus
styles from that document.@a4sriniv reports that currently portals are not implemented like that, and (IIUC) instead all attempts to focus something inside a portal browsing context are no-ops. In this model,
document.activeElement
inside a portal would be .... null? Or the<body>
element? Andfocus
andblur
events would never fire, pre-activation.autofocus=""
behavior is undetermined.IMO, having independent focused areas is conceptually clean and simple. However, it does have the potential downside of the styling not matching user expectations. For example, if the portaled content contains a
<input type=text autofocus>
, it could have the blue focus outline, while at the same time something else on the outer page also has the blue focus outline. That'd be a pretty bad user experience, I think.Are there other problems with the independent-areas model?
The text was updated successfully, but these errors were encountered: