From 18afb7f3f32f194f72344cdf8aee87f58a1a1d6a Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 26 Oct 2022 11:08:05 -0700 Subject: [PATCH 1/2] Add explicit `focusOptions` support for `ReactFocusLock` --- src/UI.tsx | 2 ++ src/types.ts | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/UI.tsx b/src/UI.tsx index e4356d9..1302039 100644 --- a/src/UI.tsx +++ b/src/UI.tsx @@ -24,6 +24,7 @@ export const FocusOn = React.forwardRef( sideCar, className, shouldIgnore, + focusOptions, style, as, ...rest @@ -58,6 +59,7 @@ export const FocusOn = React.forwardRef( className={className} whiteList={shouldIgnore} lockProps={appliedLockProps} + focusOptions={focusOptions} as={RemoveScroll} > {children} diff --git a/src/types.ts b/src/types.ts index 4ab5000..b8b56d1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -80,7 +80,12 @@ export interface ReactFocusOnProps extends CommonProps { * @default true */ returnFocus?: ComponentProps['returnFocus'] | undefined; - + /** + * [focus-lock] control focusOptions + * @default undefined + * @see {@link https://github.com/theKashey/react-focus-lock/issues/162} + */ + focusOptions?: ComponentProps['focusOptions'] | undefined; /** * [focus-lock] allows "ignoring" focus on some elements * @see {@link https://github.com/theKashey/react-focus-lock#api} From 6587e9de45f4db69f35c885640a9d2b51b0fc0b7 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Mon, 31 Oct 2022 10:42:36 -0700 Subject: [PATCH 2/2] [PR feedback] preventScrollOnFocus API vs focusOptions --- src/UI.tsx | 4 ++-- src/types.ts | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/UI.tsx b/src/UI.tsx index 1302039..5ec08d6 100644 --- a/src/UI.tsx +++ b/src/UI.tsx @@ -24,7 +24,7 @@ export const FocusOn = React.forwardRef( sideCar, className, shouldIgnore, - focusOptions, + preventScrollOnFocus, style, as, ...rest @@ -59,7 +59,7 @@ export const FocusOn = React.forwardRef( className={className} whiteList={shouldIgnore} lockProps={appliedLockProps} - focusOptions={focusOptions} + focusOptions={preventScrollOnFocus ? { preventScroll: true } : undefined} as={RemoveScroll} > {children} diff --git a/src/types.ts b/src/types.ts index b8b56d1..1924ba3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -81,11 +81,10 @@ export interface ReactFocusOnProps extends CommonProps { */ returnFocus?: ComponentProps['returnFocus'] | undefined; /** - * [focus-lock] control focusOptions - * @default undefined - * @see {@link https://github.com/theKashey/react-focus-lock/issues/162} + * [focus-lock] prevents scroll on focus via focusOptions + * @default false */ - focusOptions?: ComponentProps['focusOptions'] | undefined; + preventScrollOnFocus?: boolean | undefined; /** * [focus-lock] allows "ignoring" focus on some elements * @see {@link https://github.com/theKashey/react-focus-lock#api}