Skip to content

Commit f5d5c2f

Browse files
authored
Merge pull request #1663 from adobe/ens83070/FORMS-20980
FORMS-20980: [SLA3] Keyboard Accessibility Broken on Date Picker with Custom Display Format (AEM Forms 6.5 SP21 – Core Components 1.1.62) @sunnym @vavarshn
1 parent abc9462 commit f5d5c2f

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/clientlibs/site/js/datepickerwidget.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ if (typeof window.DatePickerWidget === 'undefined') {
306306
widget.onblur = deactivateField;
307307

308308
if (options.showCalendarIcon) {
309+
let existingCalendarIcons = widget.parentNode.querySelectorAll('.cmp-adaptiveform-datepicker__calendar-icon');
310+
existingCalendarIcons.forEach(icon => icon.remove());
311+
309312
let calendarIcon = document.createElement("div");
310313
calendarIcon.classList.add("cmp-adaptiveform-datepicker__calendar-icon");
311314

@@ -320,6 +323,9 @@ if (typeof window.DatePickerWidget === 'undefined') {
320323
});
321324
calendarIcon.addEventListener("keydown", function (event) {
322325
if (event.keyCode === 32 || event.keyCode === 13) {
326+
event.preventDefault();
327+
event.stopPropagation();
328+
self._iconClicked = true;
323329
widget.click();
324330
}
325331
});
@@ -418,9 +424,11 @@ if (typeof window.DatePickerWidget === 'undefined') {
418424
if (evnt.target.classList.contains("cmp-adaptiveform-datepicker__calendar-icon")) {
419425
if (!DatePickerWidget.#visible) {
420426
this.#show();
421-
return;
427+
handled = true;
428+
} else {
429+
this.$focusedDate.classList.add("dp-focus");
430+
handled = true;
422431
}
423-
this.$focusedDate.classList.add("dp-focus");
424432
}
425433
break;
426434
case 40: //down arrow key

ui.tests/test-module/specs/datepicker/datepicker.runtime.cy.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,65 @@ describe("Form Runtime with Date Picker", () => {
384384
});
385385
})
386386

387+
it("should have only one calendar icon per datepicker component", () => {
388+
const [datePicker7, datePicker7FieldView] = Object.entries(formContainer._fields)[6];
389+
390+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").should("have.length", 1);
391+
cy.get(`#${datePicker7}`).find("input").focus().blur().focus().blur();
392+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").should("have.length", 1);
393+
});
394+
395+
it("should open datepicker calendar when Enter key is pressed on calendar icon", () => {
396+
const [datePicker7, datePicker7FieldView] = Object.entries(formContainer._fields)[6];
397+
398+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").focus().type("{enter}");
399+
cy.get(".datetimepicker").should("be.visible");
400+
cy.get("body").click(10, 10);
401+
cy.get(".datetimepicker").should("not.be.visible");
402+
});
403+
404+
it("should open datepicker calendar when Space key is pressed on calendar icon", () => {
405+
const [datePicker7, datePicker7FieldView] = Object.entries(formContainer._fields)[6];
406+
407+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").focus().type(" ");
408+
cy.get(".datetimepicker").should("be.visible");
409+
cy.get("body").type("{esc}");
410+
cy.get(".datetimepicker").should("not.be.visible");
411+
});
412+
413+
it("should handle keyboard accessibility with custom display formats", () => {
414+
const [datePicker7, datePicker7FieldView] = Object.entries(formContainer._fields)[6];
415+
416+
cy.get(`#${datePicker7}`).find("input").should("have.attr", "type", "text"); // Custom format uses text input
417+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").should("have.attr", "tabindex", "0");
418+
cy.get(`#${datePicker7}`).find("input").focus().tab();
419+
cy.focused().should("have.class", "cmp-adaptiveform-datepicker__calendar-icon");
420+
cy.focused().type("{enter}");
421+
cy.get(".datetimepicker").should("be.visible");
422+
cy.get("body").type("{esc}");
423+
cy.get(".datetimepicker").should("not.be.visible");
424+
});
425+
426+
it("should prevent calendar icon duplication during component re-initialization", () => {
427+
const [datePicker7, datePicker7FieldView] = Object.entries(formContainer._fields)[6];
428+
429+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").should("have.length", 1);
430+
431+
const testDate = "15/08/2023";
432+
433+
cy.get(`#${datePicker7}`).find("input").clear().type(testDate);
434+
cy.get(`#${datePicker7}`).find("input").focus().blur().focus().blur();
435+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").click();
436+
cy.get(".datetimepicker").should("be.visible");
437+
cy.get("body").click(10, 10);
438+
cy.get(".datetimepicker").should("not.be.visible");
439+
cy.get(`#${datePicker7}`).find("input").clear();
440+
cy.get(`#${datePicker7}`).find("input").focus().blur();
441+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").should("have.length", 1);
442+
cy.get(`#${datePicker7}`).find(".cmp-adaptiveform-datepicker__calendar-icon").focus().type("{enter}");
443+
cy.get(".datetimepicker").should("be.visible");
444+
cy.get("body").type("{esc}");
445+
387446
// Mobile Touch Functionality Tests
388447
describe("Mobile Touch Functionality", () => {
389448
beforeEach(() => {

0 commit comments

Comments
 (0)