Skip to content

Commit

Permalink
Make sure not to lose track of focus when we rebuild the inner fields.
Browse files Browse the repository at this point in the history
Removing the inner field while focused nulls out the active element, without a
blur event of course, so this means that we left the :focus state in the input
set incorrectly, plus that we actually lost focus.

Differential Revision: https://phabricator.services.mozilla.com/D12106

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1450219
gecko-commit: 6da0db82505cb9e55b15c4306725503cf168553d
gecko-integration-branch: central
gecko-reviewers: Gijs
  • Loading branch information
emilio authored and moz-wptsync-bot committed Nov 16, 2018
1 parent 44a54b7 commit 25ac920
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<meta charset=utf-8>
<title>input type=date and input type=datetime handle focus state correctly</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/input.html#time-state-(type=time)">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1450219">
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="author" title="Mozilla" href="https://mozilla.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<input type="time">
<input type="text">
<script>
let t = async_test("Time input handles focus correctly when value changes");
window.onload = t.step_func_done(function() {
let time = document.querySelector("input[type=time]");
let text = document.querySelector("input[type=text]");
time.focus();
assert_true(time.matches(":focus"));
assert_equals(document.activeElement, time);
time.value = "08:10:10";
assert_true(time.matches(":focus"));
assert_equals(document.activeElement, time);
time.value = "08:10";
assert_true(time.matches(":focus"));
assert_equals(document.activeElement, time);
text.focus();
assert_true(text.matches(":focus"));
assert_false(time.matches(":focus"));
assert_equals(document.activeElement, text);
});
</script>

0 comments on commit 25ac920

Please sign in to comment.