-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
a89135b
commit 8b6abad
Showing
4 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<button id="one">one</button> | ||
<button id="two" autofocus>two</button> | ||
<button id="three">three</button> | ||
<script> | ||
function messageHandler(e) { | ||
if (e.data === 'check-active-element') { | ||
let autofocusedButton = document.querySelector('#two'); | ||
e.source.postMessage(document.activeElement === autofocusedButton); | ||
} | ||
} | ||
|
||
window.portalHost.onmessage = messageHandler; | ||
window.onportalactivate = e => { | ||
let portal = e.adoptPredecessor(); | ||
portal.onmessage = messageHandler; | ||
document.body.appendChild(portal); | ||
} | ||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters