Skip to content

Commit

Permalink
Merge pull request #3239 from mi6/2244-ic-date-input-improve-deletion…
Browse files Browse the repository at this point in the history
…-of-full-date-via-keyboard

2244 ic date input improve deletion of full date via keyboard
  • Loading branch information
GCHQ-Developer-530 authored Feb 24, 2025
2 parents 6a3c149 + 534252c commit aea384c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,30 @@ describe("IcDateInput end-to-end, visual regression and a11y tests", () => {
cy.findShadowEl(DATE_INPUT, YEAR_INPUT_ARIA_LABEL).should(HAVE_VALUE, "");
});

it("should test deleting the date using backspace", () => {
mount(<IcDateInput label="Test Label" />);

cy.checkHydrated(DATE_INPUT);

cy.findShadowEl(DATE_INPUT, DAY_INPUT_ARIA_LABEL).type("30");
cy.findShadowEl(DATE_INPUT, MONTH_INPUT_ARIA_LABEL).type("04");
cy.findShadowEl(DATE_INPUT, YEAR_INPUT_ARIA_LABEL).type("2000");

cy.findShadowEl(DATE_INPUT, YEAR_INPUT_ARIA_LABEL).type(
"{Backspace}{Backspace}{Backspace}{Backspace}"
);
cy.findShadowEl(DATE_INPUT, MONTH_INPUT_ARIA_LABEL).type(
"{Backspace}{Backspace}"
);
cy.findShadowEl(DATE_INPUT, DAY_INPUT_ARIA_LABEL).type(
"{Backspace}{Backspace}"
);

cy.findShadowEl(DATE_INPUT, DAY_INPUT_ARIA_LABEL).should(HAVE_VALUE, "");
cy.findShadowEl(DATE_INPUT, MONTH_INPUT_ARIA_LABEL).should(HAVE_VALUE, "");
cy.findShadowEl(DATE_INPUT, YEAR_INPUT_ARIA_LABEL).should(HAVE_VALUE, "");
});

it("should enter complete date and check for accessibility", () => {
mount(
<div style={{ padding: "10px" }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,12 @@ export class DateInput {
this.preventAutoFormatting = true;
this.handleUpDownArrowKeyPress(input, event);
break;
case "backspace":
if (input.value.length === 0) {
event.preventDefault();
this.moveToPreviousInput(input);
}
break;
default:
break;
}
Expand Down

0 comments on commit aea384c

Please sign in to comment.