Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /mathml/relations/html5-tree/autofocus-004.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>MathML autofocus attribute</title>
<script src="/mathml/support/mathml-fragments.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test("dynamically set autofocus on element");
let div = document.createElement("div");
// Create the MathML element with dynamically set autofocus.
var element = FragmentHelper.createElement("math");
test(_ => {
assert_false(element.autofocus);
assert_false(element.hasAttribute("autofocus"));
element.autofocus = true;
assert_true(element.autofocus);
assert_true(element.hasAttribute("autofocus"));
}, "setting autofocus attribute");
element.tabIndex = 1;
element.innerHTML = "<mtext>math</mtext>";
element.addEventListener("focus", t.step_func_done(function(e) {
assert_true(document.activeElement == e.target, "<mrow> element is focused");
}, "focus() called on <mrow> element"));
div.appendChild(element);
// Create the input tag to finish early in case of failure.
let input = document.createElement("input");
input.autofocus = true;
input.value = "input";
input.addEventListener("focus",
t.unreached_func("focus() shouldn't be called on `<input>`"));
div.appendChild(input);
document.body.appendChild(div);
</script>