Skip to content

Commit 4d6199e

Browse files
committed
Readonly date input can be edited via keyboard
https://bugs.webkit.org/show_bug.cgi?id=306307 rdar://169488939 Reviewed by Ryosuke Niwa. Fix readonly date input picker opening via space key by adding an isMutable() guard to didReceiveSpaceKeyFromControl(), matching the existing guards in handleDOMActivateEvent() and handleAccessibilityActivation(). Test: fast/forms/date/date-editable-components/date-readonly-picker-does-not-open-on-space-keypress.html * LayoutTests/fast/forms/date/date-editable-components/date-readonly-picker-does-not-open-on-space-keypress-expected.txt: Added. * LayoutTests/fast/forms/date/date-editable-components/date-readonly-picker-does-not-open-on-space-keypress.html: Added. * Source/WebCore/html/BaseDateAndTimeInputType.cpp: (WebCore::BaseDateAndTimeInputType::didReceiveSpaceKeyFromControl): Canonical link: https://commits.webkit.org/307934@main
1 parent 5a36716 commit 4d6199e

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Tests that a readonly date input's calendar view cannot be opened using the space key.
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS showingPicker is false
7+
Focusing readonly input using tab key and then pressing space key.
8+
PASS showingPicker is false
9+
PASS document.getElementById('input').value is "1970-01-01"
10+
Removing readonly attribute and pressing space key.
11+
PASS showingPicker is true
12+
PASS successfullyParsed is true
13+
14+
TEST COMPLETE
15+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="../../../../resources/js-test.js"></script>
5+
<script src="../../../../resources/ui-helper.js"></script>
6+
</head>
7+
<body>
8+
9+
<input id="input" type="date" readonly value="1970-01-01"/>
10+
11+
<script>
12+
13+
jsTestIsAsync = true;
14+
15+
addEventListener("load", async () => {
16+
description("Tests that a readonly date input's calendar view cannot be opened using the space key.");
17+
18+
showingPicker = await UIHelper.isShowingDateTimePicker();
19+
shouldBeFalse("showingPicker");
20+
21+
debug("Focusing readonly input using tab key and then pressing space key.");
22+
UIHelper.keyDown("\t");
23+
UIHelper.keyDown(" ");
24+
await UIHelper.ensurePresentationUpdate();
25+
26+
showingPicker = await UIHelper.isShowingDateTimePicker();
27+
shouldBeFalse("showingPicker");
28+
29+
shouldBeEqualToString("document.getElementById('input').value", "1970-01-01");
30+
31+
debug("Removing readonly attribute and pressing space key.");
32+
document.getElementById("input").removeAttribute("readonly");
33+
UIHelper.keyDown(" ");
34+
await UIHelper.ensurePresentationUpdate();
35+
36+
showingPicker = await UIHelper.isShowingDateTimePicker();
37+
shouldBeTrue("showingPicker");
38+
39+
finishJSTest();
40+
});
41+
</script>
42+
43+
</body>
44+
</html>

Source/WebCore/html/BaseDateAndTimeInputType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ void BaseDateAndTimeInputType::didChangeValueFromControl()
597597

598598
void BaseDateAndTimeInputType::didReceiveSpaceKeyFromControl()
599599
{
600+
ASSERT(element());
601+
if (!element()->renderer() || !protect(element())->isMutable())
602+
return;
603+
600604
// One of our subfields received a space key event, so let's move focus into the picker.
601605
m_pickerWasActivatedByKeyboard = true;
602606
m_didTransferFocusToPicker = true;

0 commit comments

Comments
 (0)