forked from mirrors/gecko-dev
Bug 1848158 - Let keydown preventDefault work on <input type=date> r=reusable-components-reviewers,emilio,ayeddi,tgiles
Differential Revision: https://phabricator.services.mozilla.com/D208077
This commit is contained in:
parent
1e07620528
commit
69b247d1f5
3 changed files with 39 additions and 14 deletions
|
|
@ -73,6 +73,8 @@ support-files = ["file_double_submit.html"]
|
||||||
|
|
||||||
["test_input_datetime_input_change_events.html"]
|
["test_input_datetime_input_change_events.html"]
|
||||||
|
|
||||||
|
["test_input_datetime_preventDefault.html"]
|
||||||
|
|
||||||
["test_input_datetime_readonly.html"]
|
["test_input_datetime_readonly.html"]
|
||||||
|
|
||||||
["test_input_datetime_reset_default_value_input_change_event.html"]
|
["test_input_datetime_reset_default_value_input_change_event.html"]
|
||||||
|
|
|
||||||
23
dom/html/test/forms/test_input_datetime_preventDefault.html
Normal file
23
dom/html/test/forms/test_input_datetime_preventDefault.html
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<!doctype html>
|
||||||
|
<title>Test for bug 1848158</title>
|
||||||
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
<input id="input" type="date" value="1998-01-22">
|
||||||
|
<script>
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
SimpleTest.waitForFocus(function() {
|
||||||
|
let value = input.value;
|
||||||
|
|
||||||
|
input.addEventListener("keydown", function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
isnot(value, "", "should have a value");
|
||||||
|
|
||||||
|
input.focus();
|
||||||
|
synthesizeKey("KEY_Backspace");
|
||||||
|
is(input.value, value, "Value shouldn't change");
|
||||||
|
SimpleTest.finish();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
@ -650,6 +650,10 @@ this.DateTimeBoxWidget = class {
|
||||||
onKeyDown(aEvent) {
|
onKeyDown(aEvent) {
|
||||||
this.log("onKeyDown key: " + aEvent.key);
|
this.log("onKeyDown key: " + aEvent.key);
|
||||||
|
|
||||||
|
if (aEvent.defaultPrevented) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (aEvent.key) {
|
switch (aEvent.key) {
|
||||||
// Toggle the picker on Space/Enter on Calendar button or Space on input,
|
// Toggle the picker on Space/Enter on Calendar button or Space on input,
|
||||||
// close on Escape anywhere.
|
// close on Escape anywhere.
|
||||||
|
|
@ -691,9 +695,6 @@ this.DateTimeBoxWidget = class {
|
||||||
aEvent.preventDefault();
|
aEvent.preventDefault();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.isEditable()) {
|
|
||||||
// TODO(emilio, bug 1571533): These functions should look at
|
|
||||||
// defaultPrevented.
|
|
||||||
// Ctrl+Backspace/Delete on non-macOS and
|
// Ctrl+Backspace/Delete on non-macOS and
|
||||||
// Cmd+Backspace/Delete on macOS to clear the field
|
// Cmd+Backspace/Delete on macOS to clear the field
|
||||||
if (aEvent.getModifierState("Accel")) {
|
if (aEvent.getModifierState("Accel")) {
|
||||||
|
|
@ -705,7 +706,6 @@ this.DateTimeBoxWidget = class {
|
||||||
this.setInputValueFromFields();
|
this.setInputValueFromFields();
|
||||||
}
|
}
|
||||||
aEvent.preventDefault();
|
aEvent.preventDefault();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "ArrowRight":
|
case "ArrowRight":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue