-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get started cleaning up interesttarget implementation [1/N]
This is the first in a series of patches to clean up and update the `interesttarget` implementation to match recent OpenUI discussions. This CL: - Gets rid of `interestaction`. See the large comment posted here: openui/open-ui#1064 (comment) - Adds a connection to `InterestLost` when elements are de-focused. - Adds support (tentatively) for dialogs being shown modally. - Remove keyboard/focus support for `interesttarget`. This will get re-added later in its new form, via a hotkey rather than focus. Bug: 326681249 Change-Id: I26f07a00c4fb1d2b1da92b64d91f330c02a11468 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6166890 Auto-Submit: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Commit-Queue: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/main@{#1408202}
- Loading branch information
1 parent
f98387d
commit ed55e1d
Showing
8 changed files
with
82 additions
and
430 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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
<!doctype html> | ||
<!DOCTYPE html> | ||
<meta charset="utf-8" /> | ||
<meta name="author" title="Keith Cirkel" href="mailto:[email protected]" /> | ||
<meta name="author" title="Luke Warlow" href="mailto:[email protected]" /> | ||
<link rel="help" href="https://open-ui.org/components/interest-invokers.explainer/" /> | ||
<link | ||
rel="help" | ||
href="https://open-ui.org/components/interest-invokers.explainer/" | ||
/> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
|
@@ -20,63 +23,35 @@ | |
const slot = shadow.appendChild(document.createElement("slot")); | ||
let childEvent = null; | ||
let childEventTarget = null; | ||
let childEventInvoker = null; | ||
let childEventSource = null; | ||
let hostEvent = null; | ||
let hostEventTarget = null; | ||
let hostEventInvoker = null; | ||
slot.addEventListener( | ||
"interest", | ||
(e) => { | ||
let hostEventSource = null; | ||
slot.addEventListener("interest", (e) => { | ||
childEvent = e; | ||
childEventTarget = e.target; | ||
childEventInvoker = e.invoker; | ||
}, | ||
{ once: true }, | ||
); | ||
host.addEventListener( | ||
"interest", | ||
(e) => { | ||
childEventSource = e.source; | ||
}, { once: true }); | ||
host.addEventListener("interest", (e) => { | ||
hostEvent = e; | ||
hostEventTarget = e.target; | ||
hostEventInvoker = e.invoker; | ||
}, | ||
{ once: true }, | ||
); | ||
hostEventSource = e.source; | ||
}, { once: true }); | ||
const event = new InterestEvent("interest", { | ||
bubbles: true, | ||
invoker: slot, | ||
source: slot, | ||
composed: true, | ||
}); | ||
slot.dispatchEvent(event); | ||
assert_true(childEvent instanceof InterestEvent, "slot saw interest event"); | ||
assert_equals( | ||
childEventTarget, | ||
slot, | ||
"target is child inside shadow boundary", | ||
); | ||
assert_equals( | ||
childEventInvoker, | ||
slot, | ||
"invoker is child inside shadow boundary", | ||
); | ||
assert_equals( | ||
hostEvent, | ||
childEvent, | ||
"event dispatch propagates across shadow boundary", | ||
); | ||
assert_equals( | ||
hostEventTarget, | ||
host, | ||
"target is retargeted to shadowroot host", | ||
); | ||
assert_equals( | ||
hostEventInvoker, | ||
host, | ||
"invoker is retargeted to shadowroot host", | ||
); | ||
}, "InterestEvent propagates across shadow boundaries retargeting invoker"); | ||
assert_equals(childEventTarget, slot, "target is child inside shadow boundary"); | ||
assert_equals(childEventSource, slot, "source is child inside shadow boundary"); | ||
assert_equals(hostEvent, childEvent, "event dispatch propagates across shadow boundary"); | ||
assert_equals(hostEventTarget, host, "target is retargeted to shadowroot host"); | ||
assert_equals(hostEventSource, host, "source is retargeted to shadowroot host"); | ||
}, "InterestEvent propagates across shadow boundaries retargeting invoker source"); | ||
|
||
test(function (t) { | ||
promise_test(async (t) => { | ||
const host = document.createElement("div"); | ||
document.body.append(host); | ||
t.add_cleanup(() => host.remove()); | ||
|
@@ -86,19 +61,16 @@ | |
button.interestTargetElement = interestee; | ||
let event = null; | ||
let eventTarget = null; | ||
let eventInvoker = null; | ||
interestee.addEventListener( | ||
"interest", | ||
(e) => { | ||
let eventSource = null; | ||
interestee.addEventListener("interest", (e) => { | ||
event = e; | ||
eventTarget = e.target; | ||
eventInvoker = e.invoker; | ||
}, | ||
{ once: true }, | ||
); | ||
button.focus(); | ||
eventSource = e.source; | ||
},{ once: true }); | ||
await hoverOver(button); | ||
assert_true(!!event,"InterestEvent gets fired"); | ||
assert_true(event instanceof InterestEvent); | ||
assert_equals(eventTarget, interestee, "target is interestee"); | ||
assert_equals(eventInvoker, host, "interestee is host"); | ||
assert_equals(eventSource, host, "interestee is host"); | ||
}, "cross shadow InterestEvent retargets interestee to host element"); | ||
</script> |
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
Oops, something went wrong.