Skip to content

Commit

Permalink
feat: add NoScroll module configuration (fix #180)
Browse files Browse the repository at this point in the history
  • Loading branch information
igordanchenko committed Oct 11, 2023
1 parent a062255 commit 9f3bb7f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
19 changes: 19 additions & 0 deletions docs/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ import "yet-another-react-lightbox/styles.css";
</ul>
</td>
</tr>
<tr>
<td>noScroll</td>
<td>
&#123;<br />
&nbsp;&nbsp;disabled?: boolean;<br />
&#125;
</td>
<td>
<p>
NoScroll module settings. The NoScroll module is responsible for hiding
the vertical scrollbar and preventing document `<body/>` from scrolling
underneath the lightbox. However, in some cases, this functionality may cause
undesired side effects, so you may want to disable this feature.
</p>
<ul>
<li>`disabled` - if `true`, the NoScroll module functionality is disabled</li>
</ul>
</td>
</tr>
<tr>
<td>on</td>
<td>
Expand Down
3 changes: 3 additions & 0 deletions src/Lightbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function Lightbox({
render,
toolbar,
controller,
noScroll,
on,
plugins,
slides,
Expand All @@ -51,6 +52,7 @@ export function Lightbox({
render: defaultRender,
toolbar: defaultToolbar,
controller: defaultController,
noScroll: defaultNoScroll,
on: defaultOn,
slides: defaultSlides,
index: defaultIndex,
Expand Down Expand Up @@ -79,6 +81,7 @@ export function Lightbox({
render: { ...defaultRender, ...render },
toolbar: { ...defaultToolbar, ...toolbar },
controller: { ...defaultController, ...controller },
noScroll: { ...defaultNoScroll, ...noScroll },
on: { ...defaultOn, ...on },
...restDefaultProps,
...restProps,
Expand Down
6 changes: 4 additions & 2 deletions src/modules/NoScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ function padScrollbar(element: HTMLElement, padding: number, rtl: boolean) {
};
}

export function NoScroll({ children }: ComponentProps) {
export function NoScroll({ noScroll: { disabled }, children }: ComponentProps) {
const rtl = useRTL();

useLayoutEffect(() => {
if (disabled) return () => {};

const cleanup: (() => void)[] = [];

const { body, documentElement } = document;
Expand Down Expand Up @@ -62,7 +64,7 @@ export function NoScroll({ children }: ComponentProps) {

cleanup.forEach((clean) => clean());
};
}, [rtl]);
}, [rtl, disabled]);

return <>{children}</>;
}
Expand Down
3 changes: 3 additions & 0 deletions src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const LightboxDefaultProps: LightboxProps = {
closeOnBackdropClick: false,
},
portal: {},
noScroll: {
disabled: false,
},
on: {},
styles: {},
className: "",
Expand Down
10 changes: 9 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

/** Lightbox external props */
export type LightboxExternalProps = DeepPartial<
DeepPartial<DeepPartial<LightboxProps, "animation" | "toolbar">, "carousel", "imageProps">,
DeepPartial<DeepPartial<LightboxProps, "animation" | "toolbar" | "noScroll">, "carousel", "imageProps">,
"controller",
"ref"
>;
Expand Down Expand Up @@ -44,6 +44,8 @@ export interface LightboxProps {
controller: ControllerSettings;
/** portal settings */
portal: PortalSettings;
/** NoScroll module settings */
noScroll: NoScrollSettings;
/** lifecycle callbacks */
on: Callbacks;
/** customization styles */
Expand Down Expand Up @@ -242,6 +244,12 @@ export interface PortalSettings {
root?: DocumentFragment | Element | null;
}

/** NoScroll module settings */
export interface NoScrollSettings {
/** if `true`, the NoScroll module functionality is disabled */
disabled: boolean;
}

/** Lightbox navigation action */
export interface NavigationAction {
/** navigate through the specified number of slides */
Expand Down

0 comments on commit 9f3bb7f

Please sign in to comment.