Skip to content
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

[Gecko Bug 1765083] Introduce FocusOptions.focusVisible. #34789

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions html/interaction/focus/processing-model/focusVisible.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!doctype html>

<title>focus(options) - focusVisible</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<style>
div {
height: 10px;
border: 1px solid black;
}
</style>

<button>ABC</button>
<input>
<div id="contenteditable" contenteditable></div>
<div id="tabindex" tabindex=0></div>
<div id="not_focusable"></div>

<div id="reset_focus" tabindex=0></div>

<script>
const reset_focus = document.getElementById("reset_focus");

async function check_focus_visible(element, options, { shouldBeVisible, shouldBeFocused }) {
// Reset focus by clicking on a div, which should not show focus rings.
await test_driver.click(reset_focus);

assert_equals(document.activeElement, reset_focus, "Reset should be focused");
assert_true(reset_focus.matches(":focus"), "Clicking focusable div should match :focus");
assert_false(reset_focus.matches(":focus-visible"), "Clicking focusable div shouldn't match :focus-visible");

element.focus(options);

assert_equals(document.activeElement, shouldBeFocused ? element : reset_focus, "activeElement");
assert_equals(element.matches(":focus"), shouldBeFocused, ":focus");
assert_equals(element.matches(":focus-visible"), shouldBeVisible, ":focus-visible");
}

for (let selector of ["button", "input", "#contenteditable", "#tabindex", "#not_focusable"]) {
promise_test(async function() {
const takesKeyboardInput = selector == "#contenteditable" || selector == "input";
const shouldBeFocused = selector != "#not_focusable";

const element = document.querySelector(selector);

await check_focus_visible(element, {}, {
shouldBeVisible: takesKeyboardInput,
shouldBeFocused,
});

await check_focus_visible(element, { focusVisible: true }, {
shouldBeVisible: shouldBeFocused,
shouldBeFocused,
});
await check_focus_visible(element, { focusVisible: false }, {
shouldBeVisible: false,
shouldBeFocused,
});
}, "FocusOptions.focusVisible: " + selector);
}
</script>