Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions unitylibs/core/workflow/workflow-firefly/action-binder.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,45 @@ export default class ActionBinder {
getFocusElems() {
let elmSelector = '.drop-item';
if (this.viewport !== 'MOBILE') elmSelector = `${elmSelector}, .legal-text`;
const selector = `.inp-field, .gen-btn, ${elmSelector}`;
return Array.from(this.block.querySelectorAll(selector));
const baseSelector = `.selected-verb, .selected-model, .inp-field, .gen-btn, ${elmSelector}`;
const openVerbMenu = this.block.querySelector('.verbs-container.show-menu .verb-link');
const openModelMenu = this.block.querySelector('.models-container.show-menu .verb-link');
if (openVerbMenu || openModelMenu) {
const menuSelector = openVerbMenu ? '.verbs-container.show-menu .verb-link' : '.models-container.show-menu .verb-link';
return Array.from(this.block.querySelectorAll(menuSelector));
}
return Array.from(this.block.querySelectorAll(baseSelector));
}

isDropdownVisible = () => !this.dropdown?.classList.contains('hidden');

handleTab(event, focusableElements, dropItems, currentIndex) {
if (!focusableElements.length) return;
event.preventDefault();
const isShift = event.shiftKey;
const currentElement = document.activeElement;
const isFirstElement = currentIndex === 0;
const isLastElement = currentIndex === focusableElements.length - 1;
const openVerbMenu = this.block.querySelector('.verbs-container.show-menu');
const openModelMenu = this.block.querySelector('.models-container.show-menu');
const isMenuOpen = openVerbMenu || openModelMenu;
if (isMenuOpen) {
if ((isShift && isFirstElement) || (!isShift && isLastElement)) {
event.preventDefault();
const menuButton = openVerbMenu?.querySelector('.selected-verb') || openModelMenu?.querySelector('.selected-model');
if (menuButton) {
(openVerbMenu || openModelMenu).classList.remove('show-menu');
menuButton.setAttribute('aria-expanded', 'false');
menuButton.focus();
}
return;
}
} else {
if ((isShift && isFirstElement) || (!isShift && isLastElement)) {
this.hideDropdown();
return;
}
}
event.preventDefault();
if (currentElement.classList.contains('tip-con')) {
if (!isShift) {
const legalText = this.block.querySelector('.legal-text');
Expand All @@ -402,9 +430,7 @@ export default class ActionBinder {
}
}
}
const nextIndex = isShift
? (currentIndex - 1 + focusableElements.length) % focusableElements.length
: (currentIndex + 1) % focusableElements.length;
const nextIndex = isShift ? currentIndex - 1 : currentIndex + 1;
focusableElements[nextIndex].focus();
const newActiveIndex = dropItems.indexOf(focusableElements[nextIndex]);
this.activeIndex = newActiveIndex !== -1 ? newActiveIndex : -1;
Expand Down
Loading