Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-chart): improve touch events on hover/select #2159

Merged
merged 5 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions packages/dx-chart-core/src/utils/event-tracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,35 +195,17 @@ describe('EventTracker', () => {

it('should use touch events if available', () => {
// @ts-ignore
window.ontouchmove = true;
window.ontouchstart = true;
try {
const handlers = buildEventHandlers([series1, series2, series3] as any, {
clickHandlers: [], pointerMoveHandlers: [1] as any,
});

expect(handlers).toEqual({
touchmove: expect.any(Function),
touchleave: expect.any(Function),
touchstart: expect.any(Function),
});
} finally {
delete window.ontouchmove;
}
});

it('should use pointer events if available', () => {
// @ts-ignore
window.onpointermove = true;
try {
const handlers = buildEventHandlers([series1, series2, series3] as any, {
clickHandlers: [], pointerMoveHandlers: [1] as any,
});

expect(handlers).toEqual({
pointermove: expect.any(Function),
pointerleave: expect.any(Function),
});
} finally {
delete window.onpointermove;
delete window.ontouchstart;
}
});
});
Expand Down
8 changes: 2 additions & 6 deletions packages/dx-chart-core/src/utils/event-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,8 @@ export const buildEventHandlers = (
if (pointerMoveHandlers.length) {
const moveHandler = buildEventHandler(seriesList, pointerMoveHandlers);
const leaveHandler = buildLeaveEventHandler(pointerMoveHandlers);
if ('onpointermove' in window) {
handlers.pointermove = moveHandler;
handlers.pointerleave = leaveHandler;
} else if ('ontouchmove' in window) {
handlers.touchmove = moveHandler;
handlers.touchleave = leaveHandler;
if ('ontouchstart' in window) {
handlers.touchstart = moveHandler;
} else {
handlers.mousemove = moveHandler;
handlers.mouseleave = leaveHandler;
Expand Down
8 changes: 4 additions & 4 deletions packages/dx-react-chart/src/plugins/event-tracker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('EventTracker', () => {
it('should pass params to template', () => {
(buildEventHandlers as jest.Mock).mockReturnValue({
click: 'test-click',
pointermove: 'test-pointer-move',
pointerleave: 'test-pointer-leave',
mousemove: 'test-pointer-move',
mouseleave: 'test-pointer-leave',
});
const mock = jest.fn().mockReturnValue(null);
mount(
Expand All @@ -40,8 +40,8 @@ describe('EventTracker', () => {

expect(mock).toBeCalledWith({
onClick: 'test-click',
onPointerMove: 'test-pointer-move',
onPointerLeave: 'test-pointer-leave',
onMouseMove: 'test-pointer-move',
onMouseLeave: 'test-pointer-leave',
});
expect(buildEventHandlers).toBeCalledWith(
'test-series', { clickHandlers: [], pointerMoveHandlers: [] },
Expand Down
5 changes: 1 addition & 4 deletions packages/dx-react-chart/src/plugins/event-tracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ const EVENT_NAME_TO_REACT_MAP = {
click: 'onClick',
mousemove: 'onMouseMove',
mouseleave: 'onMouseLeave',
touchmove: 'onTouchMove',
touchleave: 'onTouchLeave',
pointermove: 'onPointerMove',
pointerleave: 'onPointerLeave',
touchstart: 'onTouchStart',
};

// Translates event names from common space to React.
Expand Down