tiny-use-detect-horizontal-overflow

1.1.2 • Public • Published

tiny-use-detect-horizontal-overflow

Small (~1 Kb) react hook for detecting items are overflown. Something like this:

https://user-images.githubusercontent.com/513452/187036364-28e55b05-2f6b-41d7-ab71-37df6b1d02a7.mp4

Usage

npm i tiny-use-detect-horizontal-overflow --save

And in your react code

import { useDetectHorizontalOverflow } from "tiny-use-detect-horizontal-overflow";

// ...

useDetectHorizontalOverflow(containerRef, (hiddenElements) => {
  console.log(hiddenElements)
  /*
    It'll print out hidden elements which are overflown by container
    (4) [li#Membeship, li#Register, li#Login, li#Learn]
  */
});

API

Usage: Let's say you have this JSX component

<div className="container" ref={containerRef}>
  <ul className="links_list" ref={listRef}>
    <li>
      <a href="/about">About</a>
    </li>
    {/*...*/}
  </ul>
</div>

And in order to use this hook:

useDetectHorizontalOverflow(
  containerRef, // react ref of container
  (entries) => {}, // callback which will be called when number of hidden element is changed
  listRef, // optional react ref for items parent - if items are not direct children of the container
  throttleTimeout // optional timeout throttle timeout for resize callback, default is 16ms
);

License

MIT

Package Sidebar

Install

npm i tiny-use-detect-horizontal-overflow

Weekly Downloads

1

Version

1.1.2

License

MIT

Unpacked Size

5.32 kB

Total Files

5

Last publish

Collaborators

  • komlev