Skip to content

Commit

Permalink
[selectors] Add new test for :focus-visible
Browse files Browse the repository at this point in the history
This test checks that when you focus an element via script,
it show a focus ring with `outline-style: auto`.
See: w3c/csswg-drafts#4278 & whatwg/html#6256

Currently Chromium and WebKit pass this test,
because despite they don't use `:focus-visible` in the UA stylesheet,
they're painting an auto style outline when an element is focused.
However Firefox fails it, because even when it uses `:-moz-focusring`
(the equivalent to `:focus-visible`) in the UA stylesheet,
it uses dotted style for the outline.
  • Loading branch information
mrego committed Jan 8, 2021
1 parent bc4c6ba commit 8199877
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions css/selectors/focus-visible-017.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<meta charset="utf-8" />
<title>CSS Test (Selectors): Programatic focus matches :focus-visible</title>
<link rel="author" title="Manuel Rego Casasnovas" href="mailto:[email protected]">
<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />
<meta name="assert" content="This test checks that using JavaScript to focus an element triggers ':focus-visible' matching, and the element shows a focus ring with 'outline-style: auto'.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@supports not (selector(:focus-visible)) {
:focus {
background-color: red;
}
}

:focus-visible {
background-color: lime;
}

:focus:not(:focus-visible) {
background-color: red;
}
</style>

<div id="target" tabindex="0">Target</div>
<script>
async_test(function(t) {
target.addEventListener("focus", t.step_func(function() {
assert_equals(getComputedStyle(target).outlineStyle, "auto", `outline-style for ${target.tagName}#${target.id} should be auto`);
assert_equals(getComputedStyle(target).backgroundColor, "rgb(0, 255, 0)", `backgroundColor for ${target.tagName}#${target.id} should be lime`);
t.done();
}));
target.focus();
}, "Programatic focus should match :focus-visible and should show a focus ring with 'outline-style: auto'");
</script>

0 comments on commit 8199877

Please sign in to comment.