@bnidev/js-utils
    Preparing search index...

    Function getFocusableElements

    • Returns an array of focusable elements within a given container. Focusable elements include links, buttons, textareas, inputs, selects, and elements with a positive tabindex.

      Parameters

      • containerOrSelector: string | HTMLElement

        A CSS selector string or an HTMLElement representing the container.

      Returns HTMLElement[]

      An array of focusable elements.

      This utility is useful for accessibility purposes, allowing you to easily find and manage focusable elements within a specific part of the DOM. It can be used in scenarios such as modal dialogs, dropdowns, or any component where you need to control focus behavior.

      // ES Module
      import { getFocusableElements } from '@bnidev/js-utils'

      // CommonJS
      const { getFocusableElements } = require('@bnidev/js-utils')
      // With a selector
      const focusables = getFocusableElements('.modal')

      // With a direct HTMLElement
      const modal = document.querySelector('.modal')
      if (modal) {
      const focusables = getFocusableElements(modal)
      }