Skip to content

Commit

Permalink
[body-scroll-lock-upgrade] Add definition (#4529)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brianzchen committed Oct 10, 2023
1 parent b6a6950 commit deb0685
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare module 'body-scroll-lock' {
declare type BodyScrollOptions = {|
reserveScrollBarGap?: boolean,
allowTouchMove?: (el: any) => boolean,
|}

declare type BodyScrollLock = {|
disableBodyScroll: (target: HTMLElement, options?: BodyScrollOptions) => void,
enableBodyScroll: (target: HTMLElement) => void,
clearAllBodyScrollLocks: () => void,
|};

declare module.exports: BodyScrollLock;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// @flow
import { describe, it } from 'flow-typed-test';
import {
disableBodyScroll,
enableBodyScroll,
clearAllBodyScrollLocks,
} from 'body-scroll-lock';

declare var element: HTMLElement;
declare var inputElement: HTMLInputElement;

describe('body-scroll-lock', () => {
it('disableBodyScroll', () => {
(disableBodyScroll(element): void);
disableBodyScroll(inputElement);
// $FlowExpectedError[incompatible-call]
disableBodyScroll();
});

it('disableBodyScroll with options', () => {
disableBodyScroll(element, {
reserveScrollBarGap: true,
allowTouchMove: (el) => true,
});
disableBodyScroll(element, {
reserveScrollBarGap: true,
});
disableBodyScroll(element, {
allowTouchMove: (el) => true,
});
// $FlowExpectedError[prop-missing]
disableBodyScroll(element, {
random: true,
});
});

it('enableBodyScroll', () => {
(enableBodyScroll(element): void);
enableBodyScroll(inputElement);
// $FlowExpectedError[incompatible-call]
enableBodyScroll();
// $FlowExpectedError[extra-arg]
enableBodyScroll(element, {});
});

it('clearAllBodyScrollLocks', () => {
(clearAllBodyScrollLocks(): void);
// $FlowExpectedError[extra-arg]
clearAllBodyScrollLocks('');
});
});

0 comments on commit deb0685

Please sign in to comment.