From 455fda973f37b0df489ba6b539aec980dbdd5e30 Mon Sep 17 00:00:00 2001 From: Anton Korzunov Date: Thu, 16 Mar 2023 19:16:18 +1100 Subject: [PATCH 1/2] fix: wire up gapMode, fixes #65 --- src/UI.tsx | 11 +++++++++-- src/types.ts | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/UI.tsx b/src/UI.tsx index 5ec08d6..4baa158 100644 --- a/src/UI.tsx +++ b/src/UI.tsx @@ -27,6 +27,7 @@ export const FocusOn = React.forwardRef( preventScrollOnFocus, style, as, + gapMode, ...rest } = props; @@ -36,12 +37,18 @@ export const FocusOn = React.forwardRef( const appliedLockProps = { ...restProps, + + as, + style, + sideCar, + shards, + allowPinchZoom, - as, + gapMode, inert, - style, + enabled: enabled && scrollLock, } as const; diff --git a/src/types.ts b/src/types.ts index 1924ba3..075cd39 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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; @@ -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 From 6327e83c9c9b3d73271c03804dfa5c566a6a35e8 Mon Sep 17 00:00:00 2001 From: Anton Korzunov Date: Thu, 16 Mar 2023 19:22:23 +1100 Subject: [PATCH 2/2] update test for scroll lock --- __tests__/scroll-lock-integration.tsx | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 __tests__/scroll-lock-integration.tsx diff --git a/__tests__/scroll-lock-integration.tsx b/__tests__/scroll-lock-integration.tsx new file mode 100644 index 0000000..8c32150 --- /dev/null +++ b/__tests__/scroll-lock-integration.tsx @@ -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( + content + ); + expect((wrapper).find(RemoveScroll).prop('gapMode')).toBe(undefined); + }); + it('gap off', async () => { + const wrapper = mount( + content + ); + expect((wrapper).find(RemoveScroll).prop('gapMode')).toBe('padding'); + }); +});