react-use-focus-within
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

react-use-focus-within

A react hook for detecting current DOM focus within an HTML element.

npm

Install

# With npm
npm i react-use-focus-within

# With Yarn
yarn add react-use-focus-within

Usage

import React from 'react'
import useFocusWithin from 'react-use-focus-within'

export default function App() {
   const ref = useRef()
   const isFocused = useFocusWithin(ref)
   // console.log(isFocused)

   return (
      <div ref={ref}>
         <ul>
            <li>
               <a href="https://github.com/">Github</a>
            </li>
            <li>
               <a href="https://npmjs.com/">NPM</a>
            </li>
            <li>
               <a href="https://react.dev/">React</a>
            </li>
         </ul>
      </div>
   )
}

Contributing

  1. Fork this repository.
  2. Create your branch: git checkout -b my-new-feature.
  3. Commit your changes: git commit -m 'Add some feature'.
  4. Push to the branch: git push origin my-new-feature.

After your pull request is merged, you can safely delete your branch.

License

This project is licensed under the MIT License - see the LICENSE file for more information.

Package Sidebar

Install

npm i react-use-focus-within

Weekly Downloads

33

Version

1.0.3

License

MIT

Unpacked Size

12.7 kB

Total Files

12

Last publish

Collaborators

  • dcooney