scrollbar-block
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

logo

A tiny library to block the scrollbar of the body element ✨

NPM Version NPM Downloads Minizip Contributors License

Live demo

Live Demo

Installation

NPM

Install

npm i scrollbar-block@latest

Use

import React, { useEffect, useState } from 'react';
import { scrollbarBlock } from 'scrollbar-block';

function Modal({ open, children }) {
  const dialogRef = React.useRef(null);
  const unlockScrollbars = React.useRef(null);

  useEffect(() => {
    const dialogNode = dialogRef.current;
    if (dialogNode) {
      if (open) {
        dialogNode.showModal();
        unlockScrollbars.current = lockScrollbars();
      } else {
        dialogNode.close();
        unlockScrollbars.current?.();
      }
    }
  }, [open]);

  return <dialog ref={dialogRef}>{children}</dialog>;
}

About

Buy Me A Coffee

Gia Hung – hung.hg

Package Sidebar

Install

npm i scrollbar-block

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

10.3 kB

Total Files

7

Last publish

Collaborators

  • hunghg255