Skip to content

Commit

Permalink
add double-click trigger (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
daynedavis authored Jun 5, 2022
1 parent 4c1c915 commit c4d6d83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"react-popper-tooltip.js": {
"bundled": 11114,
"minified": 5318,
"gzipped": 1793,
"bundled": 11456,
"minified": 5482,
"gzipped": 1813,
"treeshaked": {
"rollup": {
"code": 142,
Expand Down
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as React from 'react';
import * as PopperJS from '@popperjs/core';

export type TriggerType = 'click' | 'right-click' | 'hover' | 'focus';
export type TriggerType =
| 'click'
| 'double-click'
| 'right-click'
| 'hover'
| 'focus';

export type Config = {
/**
Expand Down
9 changes: 9 additions & 0 deletions src/usePopperTooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ export function usePopperTooltip(
return () => triggerRef.removeEventListener('click', toggleTooltip);
}, [triggerRef, isTriggeredBy, toggleTooltip]);

// Trigger: double-click
React.useEffect(() => {
if (triggerRef == null || !isTriggeredBy('double-click')) return;

triggerRef.addEventListener('dblclick', toggleTooltip);

return () => triggerRef.removeEventListener('dblclick', toggleTooltip);
}, [triggerRef, isTriggeredBy, toggleTooltip]);

// Trigger: right-click
React.useEffect(() => {
if (triggerRef == null || !isTriggeredBy('right-click')) return;
Expand Down

0 comments on commit c4d6d83

Please sign in to comment.