Skip to content

Commit

Permalink
Feature: export useMousetrap hook
Browse files Browse the repository at this point in the history
  • Loading branch information
forabi committed Mar 21, 2019
1 parent 7754765 commit f2bb8e4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/components/RangeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 6 additions & 1 deletion src/components/TimeGridScheduler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useMousetrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element | null>,
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit f2bb8e4

Please sign in to comment.