Skip to content
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
11 changes: 11 additions & 0 deletions src/components/shared/chart/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ export class ChartCanvas<Item> extends React.Component<

_onDoubleClick = () => {
this.props.onDoubleClickItem(this.state.hoveredItem);

if (this.props.stickyTooltips) {
// The double click is received as a sequence of click + click + dblclick.
// The each click sets the selectedItem inside _onClick.
//
// Unset the selectedItem here to differentiate the behavior between
// the single click vs the double clicks.
this.setState(() => ({
selectedItem: null,
}));
}
};

_getHoveredItemInfo = (): React.ReactNode => {
Expand Down
18 changes: 16 additions & 2 deletions src/test/components/MarkerChart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ describe('MarkerChart', function () {
// No tooltip displayed yet
expect(document.querySelector('.tooltip')).toBeFalsy();

function leftClick(pos: { x: CssPixels; y: CssPixels }) {
function leftClick(pos: { x: CssPixels; y: CssPixels }, dblClick = false) {
const positioningOptions = {
offsetX: pos.x,
offsetY: pos.y,
Expand All @@ -333,7 +333,7 @@ describe('MarkerChart', function () {
// Because different components listen to different events, we trigger
// all the right events, to be as close as possible to the real stuff.
fireMouseEvent('mousemove', positioningOptions);
fireFullClick(canvas, positioningOptions);
fireFullClick(canvas, positioningOptions, dblClick);
flushRafCalls();
}

Expand Down Expand Up @@ -365,6 +365,20 @@ describe('MarkerChart', function () {

// Now the tooltip should not be displayed.
expect(document.querySelector('.tooltip')).toBeFalsy();

// The tooltip should be displayed also on double click.
leftClick(position, true);

// Move the mouse outside of the marker.
fireMouseEvent('mousemove', {
offsetX: 0,
offsetY: 0,
pageX: 0,
pageY: 0,
});

// The double click shouldn't make the tooltip persisted.
expect(document.querySelector('.tooltip')).toBeFalsy();
});

it('only renders a single row when hovering', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/test/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,18 @@ export function findFillTextPositionFromDrawLog(
*/
export function fireFullClick(
element: HTMLElement,
options?: FakeMouseEventInit
options?: FakeMouseEventInit,
dblClick?: boolean
) {
fireEvent(element, getMouseEvent('mousedown', options));
fireEvent(element, getMouseEvent('mouseup', options));
fireEvent(element, getMouseEvent('click', options));
if (dblClick) {
fireEvent(element, getMouseEvent('mousedown', options));
fireEvent(element, getMouseEvent('mouseup', options));
fireEvent(element, getMouseEvent('click', options));
fireEvent(element, getMouseEvent('dblclick', options));
}
}

/**
Expand Down