Skip to content

Commit

Permalink
Merge pull request #66 from theKashey/wireup-gap
Browse files Browse the repository at this point in the history
fix: wire up gapMode, fixes #65
  • Loading branch information
theKashey authored Mar 16, 2023
2 parents 67da5b7 + 6327e83 commit 47a0db0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
29 changes: 29 additions & 0 deletions __tests__/scroll-lock-integration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import {configure, mount} from 'enzyme';
import {FocusOn} from '../src/UI';
import {sidecar} from "use-sidecar";
import { RemoveScroll } from 'react-remove-scroll/UI';
import * as Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });



const tick = () => new Promise(resolve => setTimeout(resolve, 10));

const car = sidecar(() => import ('../src/sidecar'));

describe('UI', () => {
it('gap off', async () => {
const wrapper = mount(
<FocusOn sideCar={car}>content</FocusOn>
);
expect((wrapper).find(RemoveScroll).prop('gapMode')).toBe(undefined);
});
it('gap off', async () => {
const wrapper = mount(
<FocusOn sideCar={car} gapMode="padding">content</FocusOn>
);
expect((wrapper).find(RemoveScroll).prop('gapMode')).toBe('padding');
});
});
11 changes: 9 additions & 2 deletions src/UI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const FocusOn = React.forwardRef<HTMLElement, ReactFocusOnSideProps>(
preventScrollOnFocus,
style,
as,
gapMode,
...rest
} = props;

Expand All @@ -36,12 +37,18 @@ export const FocusOn = React.forwardRef<HTMLElement, ReactFocusOnSideProps>(

const appliedLockProps = {
...restProps,

as,
style,

sideCar,

shards,

allowPinchZoom,
as,
gapMode,
inert,
style,

enabled: enabled && scrollLock,
} as const;

Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as React from 'react';
import ReactFocusLock from 'react-focus-lock/UI';
import {ComponentProps} from "react";

// TODO: reuse from react-remove-scroll-bar
export type GapMode = 'padding' | 'margin';

export interface LockProps {
onMouseDown?: ((e: React.MouseEvent) => void) | undefined;

Expand Down Expand Up @@ -49,6 +52,12 @@ export interface CommonProps {
* @see https://github.com/theKashey/react-remove-scroll#usage
*/
allowPinchZoom?: boolean | undefined;
/**
* [scroll-lock] Controls how body scroll removal is supported. Possible values - `margin` or `padding`
* @default 'margin'
* @see https://github.com/theKashey/react-remove-scroll-bar#gapmode
*/
gapMode?: GapMode;

/**
* a list of elements which should be considered as a part of the lock
Expand Down

0 comments on commit 47a0db0

Please sign in to comment.