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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@libs-ui/components-click-outside

v0.2.356-1

Published

Directive phát hiện click bên ngoài hoặc bên trong element, hữu ích cho dropdowns, modals, và popups.

Readme

Click Outside Directive

Directive phát hiện click bên ngoài hoặc bên trong element, hữu ích cho dropdowns, modals, và popups.

Features

  • ✅ Detect clicks outside element
  • ✅ Detect clicks inside element
  • ✅ Auto cleanup với takeUntilDestroyed
  • ✅ Sử dụng mousedown event để catch sớm hơn
  • ✅ Standalone directive - dễ dàng import
  • ✅ TypeScript support đầy đủ

Installation

npm install @libs-ui/components-click-outside

Usage

Basic Example

import { Component } from '@angular/core';
import { LibsUiComponentsClickOutsideDirective } from '@libs-ui/components-click-outside';

@Component({
  selector: 'app-example',
  standalone: true,
  imports: [LibsUiComponentsClickOutsideDirective],
  template: `
    <div
      LibsUiComponentsClickOutsideDirective
      (outOutside)="onClickOutside($event)"
      (outInSide)="onClickInside($event)">
      Click inside or outside this element
    </div>
  `,
})
export class ExampleComponent {
  onClickOutside(event: Event): void {
    console.log('Clicked outside!', event);
  }

  onClickInside(event: Event): void {
    console.log('Clicked inside!', event);
  }
}

Dropdown Example

import { Component, signal } from '@angular/core';
import { LibsUiComponentsClickOutsideDirective } from '@libs-ui/components-click-outside';

@Component({
  standalone: true,
  imports: [LibsUiComponentsClickOutsideDirective],
  template: `
    <div class="relative">
      <button (click)="isOpen.set(!isOpen())">Toggle Dropdown</button>

      @if (isOpen()) {
        <div
          LibsUiComponentsClickOutsideDirective
          (outOutside)="isOpen.set(false)"
          class="absolute mt-2 w-48 bg-white border rounded-lg shadow-lg">
          <ul>
            <li>Option 1</li>
            <li>Option 2</li>
            <li>Option 3</li>
          </ul>
        </div>
      }
    </div>
  `,
})
export class DropdownExample {
  readonly isOpen = signal<boolean>(false);
}

Modal Example

import { Component, signal } from '@angular/core';
import { LibsUiComponentsClickOutsideDirective } from '@libs-ui/components-click-outside';

@Component({
  standalone: true,
  imports: [LibsUiComponentsClickOutsideDirective],
  template: `
    @if (showModal()) {
      <div class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center">
        <div
          LibsUiComponentsClickOutsideDirective
          (outOutside)="showModal.set(false)"
          class="bg-white p-6 rounded-lg shadow-xl">
          <h3>Modal Title</h3>
          <p>Click outside to close</p>
        </div>
      </div>
    }
  `,
})
export class ModalExample {
  readonly showModal = signal<boolean>(false);
}

API Reference

Outputs

| Property | Type | Description | | -------------- | ------- | -------------------------------- | | (outOutside) | Event | Emit khi click bên ngoài element | | (outInSide) | Event | Emit khi click bên trong element |

Important Notes

⚠️ Event Timing: Directive sử dụng AfterViewInit, event listener được setup sau khi view init.

⚠️ Event Type: Lắng nghe mousedown event thay vì click để catch event sớm hơn.

⚠️ stopPropagation: Event được stopPropagation() để tránh conflicts với parent handlers.

⚠️ Memory Leak: Tự động cleanup với takeUntilDestroyed khi directive bị destroy.

Use Cases

  • Đóng dropdown/menu khi click bên ngoài
  • Đóng modal/dialog khi click vào overlay
  • Đóng tooltip/popover khi click ra ngoài
  • Detect user interaction với element cụ thể
  • Implement click-away behavior cho custom components

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Dependencies

  • @angular/core >= 18.0.0
  • rxjs ~7.8.0

License

MIT