Skip to content

Commit

Permalink
fix(react-chart): fix zooming on IPad (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryBogomolov authored Jun 27, 2019
1 parent f7c7655 commit 41ebed6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/dx-react-chart/src/plugins/zoom-and-pan.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jest.mock('@devexpress/dx-chart-core', () => ({
attachEvents: jest.fn(),
detachEvents: jest.fn(),
getRect: jest.fn(),
getOffset: jest.fn(),
getEventCoords: jest.fn(),
isKeyPressed: jest.fn(),
isMultiTouch: jest.fn(),
}));

const DragBoxComponent = () => null;
Expand All @@ -24,6 +28,9 @@ describe('ZoomAndPan', () => {
rootRef: {
current: {},
},
layouts: {
pane: {},
},
},
};
const defaultProps = {
Expand Down Expand Up @@ -89,4 +96,19 @@ describe('ZoomAndPan', () => {
tree.unmount();
expect(detachEvents).toBeCalledTimes(3);
});

it('should call "preventDefault" in "start" handler', () => {
const tree = mount((
<PluginHost>
{pluginDepsToComponents(defaultDeps)}
<ZoomAndPan {...defaultProps} />
</PluginHost>
));
const preventDefault = jest.fn();
const { onStart } = tree.find('ZoomPanProvider').props() as any;

onStart({ preventDefault });

expect(preventDefault).toBeCalled();
});
});
6 changes: 6 additions & 0 deletions packages/dx-react-chart/src/plugins/zoom-and-pan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ class ZoomAndPanBase extends React.PureComponent<ZoomAndPanProps, ZoomAndPanStat
}

handleStart(zoomRegionKey: string, e: any) {
// Default browser behavior is prevented in "move" handler. It is not enough for IPad.
// Calling "preventDefault" here (on "start") works for IPad.
// Going further, since we have to call "preventDefault" on "start" we may try to get rid of
// "preventDefault" on move.
// TODO: Try to remove "preventDefault" from "move" handler.
e.preventDefault();
this.offset = getOffset(e.currentTarget);
const coords = getEventCoords(e, this.offset);
// Rectangle mode should be canceled if "zoomRegionKey" is released during mouse movevent or
Expand Down

0 comments on commit 41ebed6

Please sign in to comment.