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

Add onfocusin and onfocusout attribute event listeners #45432

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
53 changes: 53 additions & 0 deletions html/dom/elements/global-attributes/onfocusin-onfocusout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<link rel=author href="mailto:[email protected]">
<link rel=help href="https://github.com/whatwg/html/issues/10234">
<link rel=help href="https://github.com/whatwg/html/issues/3514">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<div id=setfromhtml tabindex=0
onfocusin="window.firedFocusin = true"
onfocusout="window.firedFocusout = true">
onfocusin/out set from html
</div>

<div id=setfromscript tabindex=0>onfocusin/out set from script</div>

<script>
window.firedFocusin = false;
window.firedFocusout = false;

test(() => {
assert_false(window.firedFocusin,
'firedFocusin should be false at the start of the test.');
assert_false(window.firedFocusout,
'firedFocusout should be false at the start of the test.');

setfromhtml.focus();
assert_true(window.firedFocusin,
'onfocusin should be called when set from html.');
assert_false(window.firedFocusout,
'firedFocusout should be false after focusing the element.');

setfromhtml.blur();
assert_true(window.firedFocusout,
'onfocusout should be called when set from html.');
}, 'onfocusin and onfocusout should both work when set from html.');

test(() => {
let firedFocusinFromScript = false;
let firedFocusoutFromScript = false;
setfromscript.onfocusin = () => firedFocusinFromScript = true;
setfromscript.onfocusout = () => firedFocusoutFromScript = true;

setfromscript.focus();
assert_true(firedFocusinFromScript,
'onfocusin should be called after focusing the element.');
assert_false(firedFocusoutFromScript,
'onfocusout should not be called after focusing the element.');

setfromscript.blur();
assert_true(firedFocusoutFromScript,
'onfocusout should be called after blurring the element.');
}, 'onfocusin and onfocusout should both work when set from script.');
</script>