Skip to content
WingoUI
ComponentsTemplatesDocsPricingAI agentsBlogChangelogContact
Components
Buttons & Actions
ButtonButton GroupCopy ButtonDelete ButtonTheme ToggleToggleToggle Group
Inputs
Avatar UploadCalendarCheckboxColor PickerComboboxCountry SelectCron PickerCurrency InputDate PickerDate Range PickerDate Time PickerDuration PickerEmail InputEmoji PickerFile UploadFilter BuilderInputInput GroupListboxMasked InputMention InputMonth PickerMulti SelectNumber InputOTP InputPassword InputPhone InputRadio GroupRatingSearch InputSegmented ControlSelectSignature PadSliderSwitchTag InputTextareaTime PickerTimezone SelectTree Select
Forms
Address InputBooking WidgetCSV ImportFieldForm WizardInline EditInvoice line itemsRich Text EditorSchema Builder
Navigation
Back To TopBounce SidebarBreadcrumbCommand MenuGlobal SearchGooey NavHook SidebarNav MenuNav TabsPaginationProximity SidebarScroll ProgressSidebarStepsTable Of ContentsTabsTopbarUser MenuWorkspace Switcher
Overlays
Alert DialogContext MenuDialogDrawerDropdown MenuFamily DrawerHover CardPopoverShare DialogSheetShortcuts DialogTooltipTour
Feedback
AlertBannerCookie ConsentEmoji ReactionEmpty StateNotification BellNotification CenterProgressRoute ProgressSetup ChecklistSkeletonSpinnerToast
Data Display
Approval FlowAvatarBadgeCalendar ViewCode BlockComment ThreadContact cardCountdownDescription ListDiff ViewerFile ListFile managerFolderGanttJSON ViewerKbdLog ViewerMarkdownPresenceSchedulerTagTimelineTree View
Tables & Lists
Audit LogData TableDeal PipelineEditable GridKanbanListMembers tablePermissions MatrixTableTask ListVirtual List
Charts & Stats
Animated CounterArea chartBar chartDonut chartFunnel chartGaugeGitHub ActivityHeatmap calendarLeaderboardLine chartRadar chartRadial barSparklineStat CardTrackerTrend badge
Layout
AccordionApp ShellCardCollapsibleDetail LayoutEntity HeaderPage HeaderScroll AreaSeparatorSettings LayoutSplit ViewToolbar
Media
Audio PlayerCarouselCSV ViewerDOCX EditorDOCX ViewerExcel ViewerFile SystemImage compareImage CropperImage GalleryImage LightboxLocation MapPDF ViewerPowerPoint ViewerQR CodeStep PlayerVideo Player
AI Kit
Agent Status CardChat MessageChat ThreadChat WidgetConversation ListFluid OrbGrid RevealMatrix OrbModel PickerPrompt InputReasoning IndicatorRule BuilderSuggestion ChipsTool Call TimelineUsage MeterVoice InputWorkflow Canvas
Text & Effects
Background PatternGravity LettersMarqueeTerminalText AnimateText Rotate
Mobile
Action SheetBottom Tab BarFABHaptic ButtonHero HeaderInstall PromptLarge Title HeaderNotification BannerOnboarding CarouselPicker WheelPull To RefreshSlide To ConfirmSticky CTA BarSwipe DeckSwipeable Tabs
Commerce
Cart drawerCategory pickerCheckout stepsCoupon inputFavorite buttonFilter panelListing cardListing gridOrder trackerPricePrice rangePricing tableProduct galleryQuantity stepperReviewsSeller card
Marketing Sections
App Download SectionBlog Cards SectionCTA SectionFAQ SectionFeature GridFeature ShowcaseHero SectionIntegrations SectionLogo CloudMarketing FooterMarketing HeaderMarketing SectionNewsletter SectionPricing SectionStats SectionSteps SectionTeam SectionTestimonials SectionTimeline SectionVideo Section
Blocks
Admin Dashboard PageAdmin ShellAI Chat PageAPI Keys PageAutomation Builder PageCheckout PageCRM Contact PageCRM Pipeline PageError PagesInbox PageInvoice PageKPI DashboardListing Detail PageLogin PageMarketplace Home PageMarketplace Search PageMarketplace ShellMobile App HomeOnboarding FlowOrder History PagePost Listing WizardPricing PageProfile PageRegister PageSettings PageUsers Admin Page
Templates
About PageAcademy PageAccessibility PageAffiliate PageAgency PageAI Product PageAppointment Booking PageBlog PageBlog Post PageBug Bounty PageCareers PageChangelog PageCommunity PageCompare PageContact PageCustomer Story PageCustomers PageDemo Booking PageDevelopers PageDocs Home PageDownload PageEnterprise PageEvents PageExperts PageFAQ PageFeature PageGlossary PageHelp Article PageHelp Center PageHome Services PageImpact PageIntegration Detail PageIntegrations PageJob Detail PageLanding PageLaunch PageLegal PageManifesto PagePortfolio PagePress PageProduct Tour PagePromo PageReal Estate PageReferral PageResearch Report PageRestaurant PageRoadmap PageROI Calculator PageSecurity PageSolutions PageStartups PageStatus PageStorefront PageSwitch PageTemplate Gallery PageTravel PageWaitlist PageYear in Review Page
Hooks & Utilities
AI ChatChart kitCommerceDate utilsFile exportFile typesFiltersForm validationHapticsInvoicingMotion presetsNavigationNumber formatRelative timeRomanian locationsSpreadsheetText matchTonesUIProvideruseClipboarduseConsentuseControllableStateuseCooldownuseDebounceuseKeyboardInsetuseLocaleuseLongPressuseMediaControlsuseMediaQueryuseOverflowItemsusePersistedStateuseScrollEdgesuseScrollStateuseSelectionuseShortcutuseStickToBottom
GalleryTheme

Hooks & Utilities

useLongPress

Hooks & Utilities

useLongPress React hook in TypeScript

useLocaleuseMediaControls
Live props
Options
delay450ms
slop8px
pointerTypes
haptics
disabled
  1. Home
  2. Components
  3. Hooks & Utilities
  4. useLongPress
Free

useLongPress React hook in TypeScript

v1.0.0·Added in 1.0.0

A React long press hook for touch screens: handlers that fire after a hold, cancel on scroll and swallow the click that follows.

Press and hold a message on a phone: it shrinks while you hold, then a reaction bar pops up and the phone buzzes where it can. Move your finger or scroll and nothing fires. With a mouse, right-click opens the same bar, or add mouse to pointerTypes in the playground to hold with the mouse too.

useLongPress is a free React hook in the React hooks and utilities category, written in TypeScript for React 19. It installs as source with npx wingo-ui@latest add use-long-press, together with Motion presets.

Add to a project

Requirements: React 19, in Next.js (App Router or Pages), Vite or React Router. Installation guide · Next.js setup · Vite setup

npx wingo-ui@latest add use-long-press

Usage

Import useLongPress from @/hooks/use-long-press.

import { useState } from "react"
import { useLongPress } from "@/hooks/use-long-press"

export function MessageBubble({ text }: { text: string }) {
  const [menu, setMenu] = useState(false)
  const longPress = useLongPress<HTMLDivElement>(() => setMenu(true))

  return (
    <div
      {...longPress}
      onContextMenu={(event) => {
        // right-click with a mouse opens the same menu
        longPress.onContextMenu(event)
        event.preventDefault()
        setMenu(true)
      }}
      className="select-none rounded-2xl bg-foreground/5 px-3 py-2 [-webkit-touch-callout:none]"
    >
      {text}
      {menu && <span>Reactions</span>}
    </div>
  )
}

API

  • onLongPress*
    (event: LongPressEvent<T>) => void

    useLongPress(onLongPress, options?): runs once the press has been held for delay ms. Gets the target element, the pointer position (clientX / clientY) and the pointer type.

  • delaydefault 450
    number

    Hold time in ms before it fires. The default is gestures.longPress from lib/motion, shared by every long press in the library.

  • slopdefault 8
    number

    How far in px the pointer may move before the press is cancelled, so scrolling a list never fires it (gestures.slop).

  • pointerTypesdefault "touch, pen"
    readonly ("touch" | "pen" | "mouse")[]

    Which pointers can long press. A mouse is left out by default because right-click does the same job there.

  • hapticsdefault true
    boolean

    A 10ms vibration when it fires, on devices that support it (Android). Silently skipped elsewhere.

  • disableddefault false
    boolean

    Ignores every press.

  • onStart / onCancel / onFinish
    (event: LongPressEvent<T>) => void / () => void / () => void

    A press began (start a holding style), ended before firing (released early, moved, scrolled), or the finger lifted after it fired.

  • returns
    LongPressHandlers<T>

    onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onPointerLeave, onContextMenu and onClickCapture, to spread on the element (or on a Radix trigger through asChild, which merges them). Add select-none [-webkit-touch-callout:none] to the element so iOS shows no callout.

Parts

  • LongPressEvent

    type

    What onLongPress and onStart receive: { target, clientX, clientY, pointerType }.

  • UseLongPressOptions

    type

    The options object: delay, slop, disabled, pointerTypes, haptics, onStart, onCancel and onFinish.

  • LongPressHandlers

    type

    The returned pointer, context menu and click capture handlers to spread on the element.

  • LongPressPointerType

    type

    "touch" | "pen" | "mouse", the values pointerTypes accepts.

Examples

Hold to confirm

A 1.2 second hold deletes; the fill grows while you press and resets if you let go.

Tap opens, hold selects

A photo grid where a long press enters selection mode and the click after it is swallowed.

Dependencies

motion

Files

  • hooks/use-long-press.ts

FAQ

Is the useLongPress hook free?

Yes. The source is free and needs no account: copy it from the Code tab or install it with the CLI.

How do I install useLongPress?

Run npx wingo-ui@latest add use-long-press. It also adds the Wingo UI item it builds on (Motion presets). With shadcn, run npx shadcn@latest add https://wingo-ui.com/r/use-long-press.json.

See also

Context MenuHaptic ButtonuseShortcuthookuseMediaQueryhookMotion presetslib

Used in

TooltipFile managerWorkflow CanvasData TableContext MenuComment ThreadFile ListGanttJSON ViewerSchedulerEditable GridList

and 4 more.

More React hooks and utilities

useMediaControlshookuseOverflowItemshookusePersistedStatehookuseScrollEdgeshookuseScrollStatehookuseSelectionhook
All 36 React hooks and utilities
PrevioususeLocaleNext useMediaControls
Hi! Is the bike still available?6:02 PM
Yes, you can see it tomorrow in Brooklyn, near Prospect Park.6:04 PM
Great, I will come at 10. Would you take $1,200?6:05 PM
useLongPress(react, { delay: 450, slop: 8 })

Right-click a message to reactPress and hold a message to react