Skip to content

Commit 651974d

Browse files
committed
fix: update controller element when disabled prop updates #151
1 parent d34092d commit 651974d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/components/Parallax/index.test.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,50 @@ describe('given the <Parallax> component', () => {
218218
expect(controller.updateElementPropsById).toHaveBeenCalledTimes(2);
219219
});
220220

221+
it('then it handles disabled prop updates', () => {
222+
const controller = ParallaxController.init({
223+
scrollAxis: ScrollAxis.vertical,
224+
});
225+
controller.updateElementPropsById = jest.fn();
226+
controller.resetElementStyles = jest.fn();
227+
228+
function Wrapper(props: PropsWithChildren<{}>) {
229+
return (
230+
<MockProvider controllerMock={controller}>
231+
{props.children}
232+
</MockProvider>
233+
);
234+
}
235+
236+
const { rerender } = render(
237+
<Parallax
238+
disabled={false}
239+
translateX={[100, -100]}
240+
translateY={[-100, 100]}
241+
/>,
242+
{
243+
wrapper: Wrapper,
244+
}
245+
);
246+
247+
rerender(
248+
<Parallax
249+
disabled={true}
250+
translateX={[100, -100]}
251+
translateY={[-100, 100]}
252+
/>
253+
);
254+
255+
const element = controller.getElements()[0];
256+
257+
expect(controller.resetElementStyles).toBeCalledWith(element);
258+
expect(controller.updateElementPropsById).toBeCalledWith(element.id, {
259+
disabled: true,
260+
translateX: [100, -100],
261+
translateY: [-100, 100],
262+
});
263+
});
264+
221265
it('then it resets styles on an element if the disabled prop is true', () => {
222266
const controller = ParallaxController.init({
223267
scrollAxis: ScrollAxis.vertical,

src/hooks/useParallax.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function useParallax<T extends HTMLElement>(props: ParallaxProps) {
4242
if (element) {
4343
if (props.disabled) {
4444
controller?.resetElementStyles(element);
45+
controller?.updateElementPropsById(element.id, parallaxProps);
4546
} else {
4647
controller?.updateElementPropsById(element.id, parallaxProps);
4748
}

0 commit comments

Comments
 (0)