@benmarch/a11y-toolkit
    Preparing search index...

    Class RovingFocus

    Implements a Roving Focus or Roving Tab Index pattern: https://developer.mozilla.org/en-US/docs/Web/Accessibility/Guides/Keyboard-navigable_JavaScript_widgets#technique_1_roving_tabindex

    Ensures the only one of the provided elements can be tab-focused at any given time. The other elements will be deactivated from tabbing by setting tabindex="-1".

    The focused element can be changed by calling the focus() method with the index of the element to focus, or by calling next() or prev() to cycle.

    This is useful for implementing group-like patterns where only one element in a group should be focusable at a time.

    Index

    Constructors

    Properties

    elements: ElementList
    index: number = 0
    isActive: boolean = false

    Methods

    • Applies appropriate tabindex to all elements. Optionally focuses the active element.

      Parameters

      • shouldFocusActive: boolean = false

        If true, will immediately focus the active element

      Returns void

    • Move focus to a specific element by index

      Parameters

      • Optionalindex: number

      Returns void