UNPKG

armisa-models

Version:
95 lines (94 loc) 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToolboxTabbing = void 0; class ToolboxTabbing { get focusAbleToolbox() { return this.mainFocusAbleToolbox.filter(i => !i.disabled && i.visible && !i.hidden && typeof i.tabIndex === 'number'); } constructor(tabbing) { this.tabbing = tabbing; this.isEmpty = () => { if (!this.focusAbleToolbox) { return true; } else if (this.focusAbleToolbox.length <= 0) { return true; } return false; }; this.focus = (tryElement = true) => { let result = false; result = this.focusToActiveElementTabIndex(); if (result) { return; } result = this.focusFirstElement(); if (result) { return; } if (tryElement) { this.tabbing.elementTabbing.focusToZeroTabIndexOrFirstElementOrToolbox(); } }; ///-1 index equal to home button this.activeToolboxAtiveIndex = 0; this.isThereAnyToolboxForFocus = () => { if (this.focusAbleToolbox && this.focusAbleToolbox.length) { return this.focusAbleToolbox[0]; } return undefined; }; this.focusToActiveElementTabIndex = () => { const find = this.focusAbleToolbox.find(i => i.tabIndex === this.activeToolboxAtiveIndex); if (find && find.refOfElemetn && find.refOfElemetn.current) { find.refOfElemetn.current.focus(); } if (find) { return true; } return false; }; this.focusFirstElement = () => { if (this.focusAbleToolbox && this.focusAbleToolbox.length > 0 && this.focusAbleToolbox[0] && typeof this.focusAbleToolbox[0].tabIndex === 'number') { this.activeToolboxAtiveIndex = this.focusAbleToolbox[0].tabIndex; this.tabbing.activeElementIndex = -1; this.tabbing.focus(); return true; } return false; }; this.focuseToThisToolStripItem = (toolStripItem) => { if (toolStripItem.refOfElemetn && toolStripItem.refOfElemetn.current) { this.tabbing.activeElementIndex = -1; this.activeToolboxAtiveIndex = toolStripItem.tabIndex; toolStripItem.refOfElemetn.current.focus(); } }; this.focusNextItem = () => { const currentIndex = this.focusAbleToolbox.findIndex(i => i.tabIndex === this.activeToolboxAtiveIndex); if (currentIndex === this.focusAbleToolbox.length - 1) { this.focuseToThisToolStripItem(this.focusAbleToolbox[0]); } else { this.focuseToThisToolStripItem(this.focusAbleToolbox[currentIndex + 1]); } }; this.focusPreviousItem = () => { const currentIndex = this.focusAbleToolbox.findIndex(i => i.tabIndex === this.activeToolboxAtiveIndex); if (currentIndex === 0) { this.focuseToThisToolStripItem(this.focusAbleToolbox[this.focusAbleToolbox.length - 1]); } else { this.focuseToThisToolStripItem(this.focusAbleToolbox[currentIndex - 1]); } }; this.focusLastElementOfForm = () => { this.tabbing.elementTabbing.focusToMaxTabIndexOrLastElement(); }; this.focusFirstElementOfForm = () => { this.tabbing.elementTabbing.focusToZeroTabIndexOrFirstElementOrToolbox(); }; this.mainFocusAbleToolbox = []; } } exports.ToolboxTabbing = ToolboxTabbing;