Skip to content

Commit

Permalink
Merge pull request #2875 from mi6/2685-ic-radio---using-arrows-keys-i…
Browse files Browse the repository at this point in the history
…n-additional-field-input-changes-selected-radio

2685 ic radio   using arrows keys in additional field input changes selected radio
  • Loading branch information
GCHQ-Developer-530 authored Dec 19, 2024
2 parents 44b2de7 + fd812f6 commit 0ac34f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/react/src/component-tests/IcRadio/IcRadio.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe("IcRadio end-to-end tests", () => {
cy.get(TEXT_FIELD_SELECTOR).eq(2).should("be.visible");
});

it("should call onclick function of component in additional-field slot when slotted component is clicked", () => {
it("should call onclick function of component in additional-field slot when slotted component is clicked and not lose focus on arrow keydown", () => {
mount(<ConditionalDynamic />);
cy.get(RADIO_SELECTOR).eq(0).find(".container").click();
cy.get(TEXT_FIELD_SELECTOR).eq(0).click();
Expand All @@ -216,6 +216,8 @@ describe("IcRadio end-to-end tests", () => {
HAVE_BEEN_CALLED_WITH,
"Textfield clicked"
);
cy.realPress("ArrowDown");
cy.get(TEXT_FIELD_SELECTOR).eq(0).should(HAVE_FOCUS);
});

it("should emit icChange and icCheck events when radio option is selected", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ export class RadioGroup {
}

private handleKeyDown = (event: KeyboardEvent): void => {
const additionalFields = Array.from(
this.el.querySelectorAll('[slot="additional-field"]')
) as HTMLIcTextFieldElement[];
const activeEl = document.activeElement;
if (
additionalFields.length > 0 &&
this.radioOptions.map((el) =>
slotHasContent(el, this.ADDITIONAL_FIELD)
) &&
additionalFields.map((el) => el == activeEl)
) {
return;
}

switch (event.key) {
case "ArrowDown":
case "ArrowRight":
Expand Down

0 comments on commit 0ac34f9

Please sign in to comment.