How to use the reakit-utils.isFocusable function in reakit-utils

To help you get started, we’ve selected a few reakit-utils 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 reakit / reakit / packages / reakit-test-utils / src / press.ts View on Github external
export function press(
  key: string,
  element?: Element | null,
  options: KeyboardEventInit = {}
) {
  if (element == null) {
    element = document.activeElement || document.body;
  }

  if (!element) return;

  // We can't press on elements that aren't focusable
  if (!isFocusable(element) && element.tagName !== "BODY") return;

  // If element is not focused, we should focus it
  if (element.ownerDocument?.activeElement !== element) {
    if (element.tagName === "BODY") {
      blur();
    } else {
      focus(element);
    }
  }

  // Track event.preventDefault() calls so we bail out of keydown/keyup effects
  const defaultPrevented = subscribeDefaultPrevented(
    element,
    "keydown",
    "keyup"
  );
github reakit / reakit / packages / reakit-test-utils / src / type.ts View on Github external
export function type(
  text: string,
  element?: DirtiableElement | null,
  options: InputEventInit = {}
) {
  if (element == null) {
    element = document.activeElement;
  }

  if (!element || !isFocusable(element)) return;

  if (!isTextField(element)) {
    warning(
      true,
      "[reakit-test-utils/type]",
      "You're trying to type on an element that is not able of being typed on a keyboard."
    );
    return;
  }

  focus(element);

  // Set element dirty so blur() can dispatch a change event
  element.dirty = true;

  for (const char of text) {