From 35f7eb071dbb344b8da2d455008936e10ca1598a Mon Sep 17 00:00:00 2001 From: loganscharen <61216565+loganscharen@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:46:00 -0600 Subject: [PATCH 1/9] Fixed issue where tabbing wouldn't loop correctly for radio elements at the end of a modal --- src/helpers/scopeTab.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/helpers/scopeTab.js b/src/helpers/scopeTab.js index 1e24378a..cd9c5697 100644 --- a/src/helpers/scopeTab.js +++ b/src/helpers/scopeTab.js @@ -29,7 +29,13 @@ export default function scopeTab(node, event) { target = tail; } - if (tail === activeElement && !shiftKey) { + if ( + (tail === activeElement || + (activeElement.type === "radio" && + tail.type === "radio" && + tail.name === activeElement.name)) && + !shiftKey) + ) { target = head; } From ed2b7dc18791fa666b634e50e0501912137032c1 Mon Sep 17 00:00:00 2001 From: loganscharen <61216565+loganscharen@users.noreply.github.com> Date: Fri, 8 Mar 2024 10:04:31 -0600 Subject: [PATCH 2/9] Added test for tabbing with radio as last element --- specs/Modal.events.spec.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/specs/Modal.events.spec.js b/specs/Modal.events.spec.js index 8c9d5f2b..a6376707 100644 --- a/specs/Modal.events.spec.js +++ b/specs/Modal.events.spec.js @@ -128,6 +128,26 @@ export default () => { }); }); + it("traps tab in the modal on tab with radio button as last element", () => { + const topButton = ; + const radio1 = ; + const radio2 = ; + const modalContent = ( +
+ {topButton} + {radio1} + {radio2} +
+ ); + const props = { isOpen: true }; + withModal(props, modalContent, modal => { + const content = mcontent(modal); + tabKeyDown(content); + tabKeyDown(content); + document.activeElement.textContent.should.be.eql("top"); + }); + }); + describe("shouldCloseOnEsc", () => { context("when true", () => { it("should close on Esc key event", () => { From d11722a0d5cedeb32fa218102efa5286f70d2ab9 Mon Sep 17 00:00:00 2001 From: loganscharen <61216565+loganscharen@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:08:16 -0600 Subject: [PATCH 3/9] Moved radios to end of form --- examples/basic/forms/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/basic/forms/index.js b/examples/basic/forms/index.js index 6826a53e..c742f884 100644 --- a/examples/basic/forms/index.js +++ b/examples/basic/forms/index.js @@ -45,21 +45,21 @@ class Forms extends Component {
- Radio buttons + Checkbox buttons
- Checkbox buttons + Radio buttons
From 40232ee39970205a63dddfb2f104038c3d832b7a Mon Sep 17 00:00:00 2001 From: loganscharen <61216565+loganscharen@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:16:43 -0600 Subject: [PATCH 4/9] Moved radio check to function --- src/helpers/scopeTab.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/helpers/scopeTab.js b/src/helpers/scopeTab.js index cd9c5697..0aaefb62 100644 --- a/src/helpers/scopeTab.js +++ b/src/helpers/scopeTab.js @@ -6,6 +6,14 @@ function getActiveElement(el = document) { : el.activeElement; } +function isActiveElementInTailRadioGroup(activeElement, tail) { + return ( + activeElement.type === "radio" && + tail.type === "radio" && + tail.name === activeElement.name + ); +} + export default function scopeTab(node, event) { const tabbable = findTabbable(node); @@ -31,10 +39,8 @@ export default function scopeTab(node, event) { if ( (tail === activeElement || - (activeElement.type === "radio" && - tail.type === "radio" && - tail.name === activeElement.name)) && - !shiftKey) + isActiveElementInTailRadioGroup(activeElement, tail)) && + !shiftKey ) { target = head; } From 704521fe4c2c7dd478e3e13842a231fa254d2d99 Mon Sep 17 00:00:00 2001 From: loganscharen <61216565+loganscharen@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:16:44 -0500 Subject: [PATCH 5/9] Update src/helpers/scopeTab.js Co-authored-by: Bruno Dias --- src/helpers/scopeTab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/scopeTab.js b/src/helpers/scopeTab.js index 0aaefb62..2b04106a 100644 --- a/src/helpers/scopeTab.js +++ b/src/helpers/scopeTab.js @@ -6,7 +6,7 @@ function getActiveElement(el = document) { : el.activeElement; } -function isActiveElementInTailRadioGroup(activeElement, tail) { +function areFromSameRadioGroup(a, b) { return ( activeElement.type === "radio" && tail.type === "radio" && From 3b3fbc02afc980cf87031f01a3c59162b87058e6 Mon Sep 17 00:00:00 2001 From: loganscharen <61216565+loganscharen@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:16:49 -0500 Subject: [PATCH 6/9] Update src/helpers/scopeTab.js Co-authored-by: Bruno Dias --- src/helpers/scopeTab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/scopeTab.js b/src/helpers/scopeTab.js index 2b04106a..ca9b9a82 100644 --- a/src/helpers/scopeTab.js +++ b/src/helpers/scopeTab.js @@ -39,7 +39,7 @@ export default function scopeTab(node, event) { if ( (tail === activeElement || - isActiveElementInTailRadioGroup(activeElement, tail)) && + areFromSameRadioGroup(activeElement, tail)) && !shiftKey ) { target = head; From e94aaa1f78036c24fb6d6bca99409409dfbc769d Mon Sep 17 00:00:00 2001 From: loganscharen <61216565+loganscharen@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:19:29 -0500 Subject: [PATCH 7/9] Reverted index.js --- examples/basic/forms/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/basic/forms/index.js b/examples/basic/forms/index.js index c742f884..6826a53e 100644 --- a/examples/basic/forms/index.js +++ b/examples/basic/forms/index.js @@ -45,21 +45,21 @@ class Forms extends Component {
- Checkbox buttons + Radio buttons
- Radio buttons + Checkbox buttons
From 273f71fd9a9e5821554b91a73d435ce38f9020af Mon Sep 17 00:00:00 2001 From: loganscharen <61216565+loganscharen@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:05:03 -0500 Subject: [PATCH 8/9] Fixed lint issues --- src/helpers/scopeTab.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/helpers/scopeTab.js b/src/helpers/scopeTab.js index ca9b9a82..d19a5ecc 100644 --- a/src/helpers/scopeTab.js +++ b/src/helpers/scopeTab.js @@ -7,11 +7,7 @@ function getActiveElement(el = document) { } function areFromSameRadioGroup(a, b) { - return ( - activeElement.type === "radio" && - tail.type === "radio" && - tail.name === activeElement.name - ); + return a.type === "radio" && b.type === "radio" && a.name === b.name; } export default function scopeTab(node, event) { @@ -38,9 +34,8 @@ export default function scopeTab(node, event) { } if ( - (tail === activeElement || - areFromSameRadioGroup(activeElement, tail)) && - !shiftKey + (tail === activeElement || areFromSameRadioGroup(activeElement, tail)) && + !shiftKey ) { target = head; } From 9609eb1dc8e0b568d012c43ab83422d3d3117bec Mon Sep 17 00:00:00 2001 From: loganscharen <61216565+loganscharen@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:26:43 -0500 Subject: [PATCH 9/9] Update src/helpers/scopeTab.js Co-authored-by: Bruno Dias --- src/helpers/scopeTab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/scopeTab.js b/src/helpers/scopeTab.js index d19a5ecc..5556b310 100644 --- a/src/helpers/scopeTab.js +++ b/src/helpers/scopeTab.js @@ -7,7 +7,7 @@ function getActiveElement(el = document) { } function areFromSameRadioGroup(a, b) { - return a.type === "radio" && b.type === "radio" && a.name === b.name; + return a.name === b.name && a.type === "radio" && b.type === "radio"; } export default function scopeTab(node, event) {