How to use tabbable - 10 common examples

To help you get started, we’ve selected a few tabbable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / tabbable_v3.x.x / test_tabbable_v3.x.x.js View on Github external
// @flow

import tabbable from 'tabbable';

const div = document.createElement('div');
const tabbables: Array = tabbable(div, {
  includeContainer: true,
});

tabbable(div);

tabbables.map(node => node.nodeName);

const isTabbable: boolean = tabbable.isTabbable(document.createElement('a'));
const isFocusable: boolean = tabbable.isFocusable(
  document.createElement('button')
);

const untouchabilityChecker = new (class {
  hasDisplayNone() {
    return true;
  }
  isUntouchable() {
    return false;
  }
})();

const isTabbableWithUntouchabilityChecker: boolean = tabbable.isTabbable(
  document.createElement('a'),
  untouchabilityChecker
);
github flow-typed / flow-typed / definitions / npm / tabbable_v3.x.x / test_tabbable_v3.x.x.js View on Github external
document.createElement('a'),
  untouchabilityChecker
);

const isFocusableWithUntouchabilityChecker: boolean = tabbable.isFocusable(
  document.createElement('button'),
  untouchabilityChecker
);

const isFocusable2: boolean = tabbable.isFocusable(
  document.createElement('button'),
  // $ExpectError
  3
);

const isTabbable2: boolean = tabbable.isFocusable(
  document.createElement('button'),
  // $ExpectError
  3
);
github flow-typed / flow-typed / definitions / npm / tabbable_v3.x.x / test_tabbable_v3.x.x.js View on Github external
const untouchabilityChecker = new (class {
  hasDisplayNone() {
    return true;
  }
  isUntouchable() {
    return false;
  }
})();

const isTabbableWithUntouchabilityChecker: boolean = tabbable.isTabbable(
  document.createElement('a'),
  untouchabilityChecker
);

const isFocusableWithUntouchabilityChecker: boolean = tabbable.isFocusable(
  document.createElement('button'),
  untouchabilityChecker
);

const isFocusable2: boolean = tabbable.isFocusable(
  document.createElement('button'),
  // $ExpectError
  3
);

const isTabbable2: boolean = tabbable.isFocusable(
  document.createElement('button'),
  // $ExpectError
  3
);
github flow-typed / flow-typed / definitions / npm / tabbable_v3.x.x / test_tabbable_v3.x.x.js View on Github external
// @flow

import tabbable from 'tabbable';

const div = document.createElement('div');
const tabbables: Array = tabbable(div, {
  includeContainer: true,
});

tabbable(div);

tabbables.map(node => node.nodeName);

const isTabbable: boolean = tabbable.isTabbable(document.createElement('a'));
const isFocusable: boolean = tabbable.isFocusable(
  document.createElement('button')
);

const untouchabilityChecker = new (class {
  hasDisplayNone() {
    return true;
  }
  isUntouchable() {
    return false;
  }
})();

const isTabbableWithUntouchabilityChecker: boolean = tabbable.isTabbable(
  document.createElement('a'),
  untouchabilityChecker
github flow-typed / flow-typed / definitions / npm / tabbable_v3.x.x / test_tabbable_v3.x.x.js View on Github external
const isTabbable: boolean = tabbable.isTabbable(document.createElement('a'));
const isFocusable: boolean = tabbable.isFocusable(
  document.createElement('button')
);

const untouchabilityChecker = new (class {
  hasDisplayNone() {
    return true;
  }
  isUntouchable() {
    return false;
  }
})();

const isTabbableWithUntouchabilityChecker: boolean = tabbable.isTabbable(
  document.createElement('a'),
  untouchabilityChecker
);

const isFocusableWithUntouchabilityChecker: boolean = tabbable.isFocusable(
  document.createElement('button'),
  untouchabilityChecker
);

const isFocusable2: boolean = tabbable.isFocusable(
  document.createElement('button'),
  // $ExpectError
  3
);

const isTabbable2: boolean = tabbable.isFocusable(
github vanilla / vanilla / applications / dashboard / src / scripts / dom.ts View on Github external
fromElement: document.activeElement,
        allowLooping: true,
    };

    // Merge the passed options and the defaults.
    const finalOptions = {
        ...defaultTabbableOptions,
        ...options,
    } as ITabbableOptions;

    if (!(finalOptions.fromElement instanceof HTMLElement)) {
        logError("Unable to tab to next element, `fromElement` given is not valid: ", finalOptions.fromElement);
        return null;
    }

    const tabbables = tabbable(finalOptions.root).filter((tabbableElement: Element) => {
        // We want to excempt items that are the active item or a parent of the active item
        // because otherwise we would not be able to tab away from them.
        const elementIsActiveOrChildOfActive =
            finalOptions.fromElement === tabbableElement || tabbableElement.contains(finalOptions.fromElement);

        if (!elementIsActiveOrChildOfActive) {
            if (finalOptions.excludedElements.includes(tabbableElement)) {
                return false;
            }
            for (const excludedRoot of finalOptions.excludedRoots) {
                if (excludedRoot !== tabbableElement && excludedRoot.contains(tabbableElement)) {
                    return false;
                }
            }
        }
github elastic / eui / src / components / context_menu / context_menu_panel.tsx View on Github external
// Setting focus while transitioning causes the animation to glitch, so we have to wait
      // until it's finished before we focus anything.
      if (this.state.isTransitioning) {
        return;
      }

      // If there aren't any items then this is probably a form or something.
      if (!this.state.menuItems.length) {
        // If we've already focused on something inside the panel, everything's fine.
        if (this.panel && this.panel.contains(document.activeElement)) {
          return;
        }

        // Otherwise let's focus the first tabbable item and expedite input from the user.
        if (this.content) {
          const tabbableItems = tabbable(this.content);
          if (tabbableItems.length) {
            tabbableItems[0].focus();
          }
        }
        return;
      }

      // If an item is focused, focus it.
      if (this.state.focusedItemIndex !== undefined) {
        this.state.menuItems[this.state.focusedItemIndex].focus();
        return;
      }

      // Focus on the panel as a last resort.
      if (this.panel && !this.panel.contains(document.activeElement)) {
        this.panel.focus();
github davidtheclark / focus-trap / index.js View on Github external
function checkPointerDown(e) {
    if (container.contains(e.target)) return;
    if (config.clickOutsideDeactivates) {
      deactivate({
        returnFocus: !tabbable.isFocusable(e.target)
      });
      return;
    }
    // This is needed for mobile devices.
    // (If we'll only let `click` events through,
    // then on mobile they will be blocked anyways if `touchstart` is blocked.)
    if (config.allowOutsideClick && config.allowOutsideClick(e)) {
      return;
    }
    e.preventDefault();
  }
github Blazored / Modal / src / Blazored.Modal / FocusTrap.ts View on Github external
private checkPointerDown(e): void {
        if (this.container.contains(e.target)) return;

        if (this.config.clickOutsideDeactivates) {
            this.deactivate({
                returnFocus: !tabbable.isFocusable(e.target)
            });

            return;
        }

        // This is needed for mobile devices.
        // (If we'll only let `click` events through,
        // then on mobile they will be blocked anyways if `touchstart` is blocked.)
        if (this.config.allowOutsideClick && this.config.allowOutsideClick(e)) {
            return;
        }

        e.preventDefault();
    }
github elastic / eui / src / components / datagrid / data_grid_header_row.tsx View on Github external
console.warn(
            `EuiDataGridHeaderCell expects at most 1 tabbable element, ${
              tababbles.length
            } found instead`
          );
        }
        for (let i = 0; i < tababbles.length; i++) {
          const element = tababbles[i];
          element.setAttribute('data-euigrid-tab-managed', 'true');
          element.setAttribute('tabIndex', '-1');
        }
      }

      if (isCellEntered) {
        enableInteractives();
        const tabbables = tabbable(headerRef.current!);
        if (tabbables.length > 0) {
          tabbables[0].focus();
        }
      } else {
        disableInteractives();
      }
    }
  }, [isCellEntered]);

tabbable

Returns an array of all tabbable DOM nodes within a containing node.

MIT
Latest version published 1 year ago

Package Health Score

85 / 100
Full package analysis