From f2bb8e41d7ace1a3b368d1fa78a7762d718fbe92 Mon Sep 17 00:00:00 2001 From: Muhammad Fawwaz Orabi Date: Thu, 21 Mar 2019 05:38:57 +0200 Subject: [PATCH] Feature: export useMousetrap hook --- demo/index.tsx | 2 +- src/components/RangeBox.tsx | 2 +- src/components/TimeGridScheduler.tsx | 7 ++++++- src/hooks/useMousetrap.ts | 2 +- src/index.tsx | 3 ++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/demo/index.tsx b/demo/index.tsx index c1c45c1..66ebb4a 100644 --- a/demo/index.tsx +++ b/demo/index.tsx @@ -15,7 +15,7 @@ import ReactDOM from 'react-dom'; import 'resize-observer-polyfill/dist/ResizeObserver.global'; import useUndo from 'use-undo'; import { TimeGridScheduler } from '../src/components/TimeGridScheduler'; -import useMousetrap from '../src/hooks/useMousetrap'; +import { useMousetrap } from '../src/hooks/useMousetrap'; import { classes as defaultClasses } from '../src/styles'; import { EventRootProps, ScheduleType } from '../src/types'; import DeleteIcon from './assets/outline-delete-24px.svg'; diff --git a/src/components/RangeBox.tsx b/src/components/RangeBox.tsx index 49e4c2e..9177a39 100644 --- a/src/components/RangeBox.tsx +++ b/src/components/RangeBox.tsx @@ -9,7 +9,7 @@ import React, { useState, } from 'react'; import Draggable, { DraggableEventHandler } from 'react-draggable'; -import useMousetrap from '../hooks/useMousetrap'; +import { useMousetrap } from '../hooks/useMousetrap'; import { CellInfo } from '../types'; import { EventContent } from './EventContent'; import { ScheduleProps } from './Schedule'; diff --git a/src/components/TimeGridScheduler.tsx b/src/components/TimeGridScheduler.tsx index e170969..a3ef503 100644 --- a/src/components/TimeGridScheduler.tsx +++ b/src/components/TimeGridScheduler.tsx @@ -17,7 +17,7 @@ import React, { } from 'react'; import scrollIntoView from 'scroll-into-view-if-needed'; import { useClickAndDrag } from '../hooks/useClickAndDrag'; -import useMousetrap from '../hooks/useMousetrap'; +import { useMousetrap } from '../hooks/useMousetrap'; import { CellInfo, ClassNames, @@ -316,6 +316,11 @@ export const TimeGridScheduler = React.memo(function TimeGridScheduler({ return; } + // IE, Edge do not support it + if (!('scrollBy' in root.current)) { + return; + } + root.current.scrollBy(0, top); setWasInitialScrollPerformed(true); diff --git a/src/hooks/useMousetrap.ts b/src/hooks/useMousetrap.ts index da53905..fd43257 100644 --- a/src/hooks/useMousetrap.ts +++ b/src/hooks/useMousetrap.ts @@ -7,7 +7,7 @@ import { useEffect, useRef } from 'react'; * @param handlerKey - A key, key combo or array of combos according to Mousetrap documentation. * @param handlerCallback - A function that is triggered on key combo catch. */ -export default function useMousetrap( +export function useMousetrap( handlerKey: string | string[], handlerCallback: (e: ExtendedKeyboardEvent, combo: string) => void, elementOrElementRef: typeof document | React.RefObject, diff --git a/src/index.tsx b/src/index.tsx index b78cc01..e746589 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,4 +1,5 @@ import { TimeGridScheduler } from './components/TimeGridScheduler'; +import { useMouseTrap } from './hooks/useMousetrap'; import { classes } from './styles'; -export { TimeGridScheduler, classes }; +export { TimeGridScheduler, classes, useMouseTrap };