npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@edwin2delossantos/ng-longpress

v0.0.7

Published

An Angular directive for detecting long press events.

Readme

ng-longpress

ng-longpress is an Angular directive that detects long press events on elements. When a user presses and holds the mouse button, the directive emits a typed MouseEvent repeatedly until the press is released. This package is perfect for adding custom long press behavior to your Angular applications.

Features

  • Detects long press events on any element.
  • Repeatedly emits events while the mouse button is held down.
  • Provides a typed MouseEvent for strong type-checking in TypeScript.
  • Compatible with Angular 14+ (supports standalone directives if needed).

Installation

Install the package via npm:

npm i @edwin2delossantos/ng-longpress

Usage

Importing the Module

To use the directive, import the NgLongpressModule into the Angular module where you want the directive to be available. For example, in your AppModule or any feature module:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgLongpressModule } from '@edwin2delossantos/ng-longpress';

@NgModule({
  declarations: [
    // your components here
  ],
  imports: [
    BrowserModule,
    NgLongpressModule  // Import the module to use the long press directive
  ],
  bootstrap: [/* your root component */]
})
export class AppModule { }

Using the Directive in a Template

Once the module is imported, you can use the directive in your component templates. Add the appLongPress attribute to any element and bind to its longPress event:

<div appLongPress (longPress)="onLongPress($event)">
  Press and hold this element
</div>

Handling the Long Press Event

Define an event handler in your component to respond to the long press event:

import { Component } from '@angular/core';

@Component({
  selector: 'app-example',
  templateUrl: './example.component.html'
})
export class ExampleComponent {
  onLongPress(event: MouseEvent): void {
    console.log('Long press event detected!', event);
    // Add your long press logic here
  }
}

How It Works

  • Long Press Threshold: The directive waits for 500 milliseconds after a mousedown event before emitting the first long press event.
  • Repeat Rate: Once the threshold is met, the directive emits the event repeatedly every 100 milliseconds until the user releases the mouse button or moves the cursor away.
  • Event Handling: The directive emits a typed MouseEvent for strong TypeScript integration.

Standalone vs Module Declaration

If you are using Angular 14+ and prefer to keep the directive standalone, you can mark it as standalone: true in its decorator and then import it directly. For module-based usage (recommended for libraries), ensure that the directive is not marked as standalone or, if it is, re-export it via a module as shown above.

License

This project is licensed under the MIT License.