Skip to content

Commit 58bc816

Browse files
authored
[patch] INTENG-22824: fix keyboard access to journeys and remove tabindex=-1 (#1122)
# Pull Request Template ## Description A customer's automation has found our journeys to not be WCAG compliant because our iframe that we load the journey into has tabindex = -1. What they think this is doing is making it so that the user can not tab into the journey using the keyboard. The real issues are as follows: Issue 1: CSS in the journey template at the bottom of the template (this being the template in the dashboard that the customer has the ability to edit) ``` *:focus { outline: none !important; } ``` what this is doing is making it so that when the journey is tabbed onto, you dont actually see what is being highlighted. In my own template, I updated it to ``` *:focus { outline: 2px solid blue; } ``` and now i can see that when tabbing i am actually highlighting onto various parts of the journey. Issue 2: our handling of keyboard input on the journey We created special logic to handle tabs in the journey. This function though is handling all keyboard input. So, since it is handling all keyboard input, including enter, but without any specific way to handle enter, then pressing the enter key will not do anything So, i fix the issue of keyboard input in this PR. I also removed the tabindex and added some other WCAG tags because they dont change anything, but will hopefully make the customer happy. Fixes # (issue) ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [ ] Unit test - [ ] Integration test ## JS Budget Check Please mention the size in kb before abd after this PR | Files | Before | After | | ----------- | ----------- | ----------- | | dist/build.js. | | | | dist/build.min.js| | | ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules - [ ] I have checked my code and corrected any misspellings ## Mentions: List the person or team responsible for reviewing proposed changes. cc @BranchMetrics/saas-sdk-devs for visibility.
1 parent 3a65201 commit 58bc816

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

src/0_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ config.app_service_endpoint = 'https://app.link';
99
config.link_service_endpoint = 'https://bnc.lt';
1010
config.api_endpoint = DEFAULT_API_ENDPOINT;
1111
// will get overwritten by gha on actual deploy
12-
config.version = '2.85.2';
12+
config.version = '2.86.1';

src/journeys_utils.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ journeys_utils.createIframe = function() {
248248
iframe.scrolling = 'no';
249249
iframe.id = 'branch-banner-iframe';
250250
iframe.className = 'branch-animation';
251-
iframe.setAttribute('tabindex', '-1');
251+
iframe.title = 'Branch Banner Frame';
252+
iframe.setAttribute('aria-label', 'Branch Banner Frame');
252253
utils.addNonceAttribute(iframe);
253254

254255
return iframe;
@@ -286,36 +287,52 @@ journeys_utils.addHtmlToIframe = function(iframe, html, userAgent) {
286287
var focusableContent = modal.querySelectorAll(focusableElements);
287288
var focusElementIdx = 0;
288289
289-
function handleTabKey(e) {
290+
function handleKeyboardNavigation(e) {
290291
var isTabPressed = e.key === 'Tab' || e.keyCode === 9;
291-
292-
if (!isTabPressed) {
293-
return;
294-
}
295-
296-
if (e.shifKey) {
297-
if (focusElementIdx <= 0) {
298-
focusElementIdx = focusableContent.length - 1;
292+
var isEnterPressed = e.key === 'Enter' || e.keyCode === 13;
293+
294+
// Handle Tab key for focus navigation
295+
if (isTabPressed) {
296+
if (e.shiftKey) {
297+
if (focusElementIdx <= 0) {
298+
focusElementIdx = focusableContent.length - 1;
299+
} else {
300+
focusElementIdx = focusElementIdx - 1;
301+
}
299302
} else {
300-
focusElementIdx = focusElementIdx - 1;
303+
if (focusElementIdx >= focusableContent.length - 1) {
304+
focusElementIdx = 0;
305+
} else {
306+
focusElementIdx = focusElementIdx + 1;
307+
}
301308
}
302-
} else {
303-
if (focusElementIdx >= focusableContent.length - 1) {
304-
focusElementIdx = 0;
305-
} else {
306-
focusElementIdx = focusElementIdx + 1;
309+
310+
focusableContent[focusElementIdx].focus();
311+
e.preventDefault();
312+
return;
313+
}
314+
315+
// Handle Enter key for activation
316+
if (isEnterPressed) {
317+
// Get the currently focused element
318+
var focusedElement = document.activeElement;
319+
if (focusedElement && (
320+
focusedElement.tagName === 'BUTTON' ||
321+
focusedElement.getAttribute('role') === 'button' ||
322+
focusedElement.tagName === 'A'
323+
)) {
324+
// Simulate a click on the element
325+
focusedElement.click();
326+
e.preventDefault();
307327
}
308328
}
309-
310-
focusableContent[focusElementIdx].focus();
311-
e.preventDefault();
312329
}
313330
314331
function autoFocus(delay) {
315332
setTimeout(function() { focusableContent[focusElementIdx].focus() }, delay);
316333
}
317334
318-
document.addEventListener('keydown', handleTabKey);
335+
document.addEventListener('keydown', handleKeyboardNavigation);
319336
autoFocus(100);
320337
321338
`;

test/web-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ config.app_service_endpoint = 'https://app.link';
77
config.link_service_endpoint = 'https://bnc.lt';
88
config.api_endpoint = 'https://api.branch.io';
99
// will get overwritten by gha on actual deploy
10-
config.version = '2.85.2';
10+
config.version = '2.86.1';

0 commit comments

Comments
 (0)