Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-custom-scroller",
"version": "2.2.0",
"version": "2.2.1",
"description": "Super simple React component for creating a custom scrollbar cross-browser and cross-devices",
"author": "Vitor Buzinaro <vitor@close.com>",
"license": "MIT",
Expand Down
10 changes: 6 additions & 4 deletions src/useCustomScroller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { MouseEvent as ReactMouseEvent, MutableRefObject } from 'react';
import { useLayoutEffect, useRef, useState, useCallback } from 'react';
import type { MutableRefObject, MouseEvent as ReactMouseEvent } from 'react';
import { useCallback, useLayoutEffect, useRef, useState } from 'react';

const DEFAULT_SCROLLBAR_WIDTH = 20

/**
* We use a negative right on the content to hide original OS scrollbars
*/
const OS_SCROLLBAR_WIDTH = (() => {
const OS_SCROLLBAR_WIDTH = typeof window === 'undefined' ? DEFAULT_SCROLLBAR_WIDTH : (() => {
const outer = document.createElement('div');
const inner = document.createElement('div');
outer.style.overflow = 'scroll';
Expand All @@ -24,7 +26,7 @@ const OS_SCROLLBAR_WIDTH = (() => {
* We need this for OSs that automatically hide the scrollbar (so the offset
* doesn't change in such case). Eg: macOS with "Automatically based on mouse".
*/
const SCROLLBAR_WIDTH = OS_SCROLLBAR_WIDTH || 20;
const SCROLLBAR_WIDTH = OS_SCROLLBAR_WIDTH || DEFAULT_SCROLLBAR_WIDTH;

export default function useCustomScroller(
customRef: MutableRefObject<HTMLDivElement | null> | undefined,
Expand Down