-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
CSS: :focus selector effects on shadow hosts #17493
Merged
domenic
merged 6 commits into
web-platform-tests:master
from
rakina:focusselectordelegatesFocus
Sep 24, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e153c5
CSS: :focus selector effects on shadow host with delegatesFocus
rakina bf72444
Move to shadow-dom, factor out stuff
rakina b87fd44
Update last test to not apply :focus to host
rakina d21e77b
Move to shadow-dom, factor out stuff
rakina bfdf9b8
Update tests so delegatesFocus=false also matches :focus
rakina 42557ba
remove resetFocusOnRoot
rakina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>CSS Test (Selectors): :focus behavior with shadow hosts & delegatesFocus </title> | ||
<link rel="author" title="Rakina Zata Amni" href="[email protected]" /> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/semantics-other.html#selector-focus" /> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="resources/shadow-utils.js"></script> | ||
</head> | ||
|
||
<body> | ||
<script> | ||
function createFocusableDiv() { | ||
const div = document.createElement("div"); | ||
div.innerText = "foo"; | ||
div.tabIndex = 0; | ||
return div; | ||
} | ||
|
||
function createShadowHost(delegatesFocus, container) { | ||
const host = document.createElement("div"); | ||
host.attachShadow({ mode: "open", delegatesFocus: delegatesFocus }); | ||
container.appendChild(host); | ||
return host; | ||
} | ||
|
||
const delegatesFocusValues = [true, false]; | ||
|
||
for (const delegatesFocus of delegatesFocusValues) { | ||
test(() => { | ||
resetFocus(); | ||
const host = createShadowHost(delegatesFocus, document.body); | ||
const shadowChild = createFocusableDiv(); | ||
host.shadowRoot.appendChild(shadowChild); | ||
|
||
shadowChild.focus(); | ||
assert_true(shadowChild.matches(":focus"), "element in shadow tree matches :focus"); | ||
assert_true(host.matches(":focus"), "host matches :focus"); | ||
}, `:focus applies to host with delegatesFocus=${delegatesFocus} when the shadow root's descendant has focus`); | ||
|
||
test(() => { | ||
resetFocus(); | ||
const host = createShadowHost(delegatesFocus, document.body); | ||
const slotted = createFocusableDiv(); | ||
host.shadowRoot.appendChild(document.createElement("slot")); | ||
host.appendChild(slotted); | ||
|
||
slotted.focus(); | ||
assert_true(slotted.matches(":focus"), "slotted element matches :focus"); | ||
assert_true(host.matches(":focus"), "host matches :focus"); | ||
}, `:focus applies to host with delegatesFocus=${delegatesFocus} when slotted element has focus`); | ||
|
||
for (const nestedDelegatesFocus of delegatesFocusValues) { | ||
test(() => { | ||
resetFocus(); | ||
const host = createShadowHost(delegatesFocus, document.body); | ||
const nestedHost = createShadowHost(nestedDelegatesFocus, host.shadowRoot); | ||
const nestedShadowChild = createFocusableDiv(); | ||
nestedHost.shadowRoot.appendChild(nestedShadowChild); | ||
nestedShadowChild.focus(); | ||
assert_true(nestedShadowChild.matches(":focus"), "element in nested shadow tree matches :focus"); | ||
assert_true(nestedHost.matches(":focus"), "host of nested shadow tree matches focus"); | ||
assert_true(host.matches(":focus"), "topmost host matches focus"); | ||
}, `:focus applies to host with delegatesFocus=${delegatesFocus} when an element in a nested shadow tree with delegatesFocus=${nestedDelegatesFocus} is focused`); | ||
} | ||
} | ||
</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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. If a slotted element has a focus, then the shadow host is its parent (or ancestor). If
:focus
shouldn't match both the slotted element and the host of the shadow tree to which it was assigned.I'm fixing this in #19530