From c4d6d83cf114272061748d898c8f388592997ee8 Mon Sep 17 00:00:00 2001 From: Dayne Davis Date: Sun, 5 Jun 2022 12:37:13 -0500 Subject: [PATCH] add double-click trigger (#148) --- .size-snapshot.json | 6 +++--- src/types.ts | 7 ++++++- src/usePopperTooltip.ts | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.size-snapshot.json b/.size-snapshot.json index ec87491..9977f89 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,8 +1,8 @@ { "react-popper-tooltip.js": { - "bundled": 11114, - "minified": 5318, - "gzipped": 1793, + "bundled": 11456, + "minified": 5482, + "gzipped": 1813, "treeshaked": { "rollup": { "code": 142, diff --git a/src/types.ts b/src/types.ts index 16e15f2..964e0a8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 = { /** diff --git a/src/usePopperTooltip.ts b/src/usePopperTooltip.ts index 56fe084..4387c94 100644 --- a/src/usePopperTooltip.ts +++ b/src/usePopperTooltip.ts @@ -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;