Skip to content

Commit

Permalink
fix: update controller element when disabled prop updates jscottsmith…
Browse files Browse the repository at this point in the history
  • Loading branch information
jscottsmith committed Apr 10, 2022
1 parent d34092d commit 651974d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/components/Parallax/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,50 @@ describe('given the <Parallax> component', () => {
expect(controller.updateElementPropsById).toHaveBeenCalledTimes(2);
});

it('then it handles disabled prop updates', () => {
const controller = ParallaxController.init({
scrollAxis: ScrollAxis.vertical,
});
controller.updateElementPropsById = jest.fn();
controller.resetElementStyles = jest.fn();

function Wrapper(props: PropsWithChildren<{}>) {
return (
<MockProvider controllerMock={controller}>
{props.children}
</MockProvider>
);
}

const { rerender } = render(
<Parallax
disabled={false}
translateX={[100, -100]}
translateY={[-100, 100]}
/>,
{
wrapper: Wrapper,
}
);

rerender(
<Parallax
disabled={true}
translateX={[100, -100]}
translateY={[-100, 100]}
/>
);

const element = controller.getElements()[0];

expect(controller.resetElementStyles).toBeCalledWith(element);
expect(controller.updateElementPropsById).toBeCalledWith(element.id, {
disabled: true,
translateX: [100, -100],
translateY: [-100, 100],
});
});

it('then it resets styles on an element if the disabled prop is true', () => {
const controller = ParallaxController.init({
scrollAxis: ScrollAxis.vertical,
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useParallax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function useParallax<T extends HTMLElement>(props: ParallaxProps) {
if (element) {
if (props.disabled) {
controller?.resetElementStyles(element);
controller?.updateElementPropsById(element.id, parallaxProps);
} else {
controller?.updateElementPropsById(element.id, parallaxProps);
}
Expand Down

0 comments on commit 651974d

Please sign in to comment.