Skip to content

JakeMurrayDev/OutsideClickHandler

Repository files navigation

OutsideClickHandler

Detect click outside of element for Blazor.
An improvement of Blazor.OutsideClickHandler.

What's different?

  • There's an issue that after OnClickOutside is invoked, it creates a new addeventlistener everytime creating a flood unused event listeners. This does not, it only creates one and stores OutsideClickHandler instances on a list on first render and removes it when StopPropagation is true or when the component is disposed.
  • There's also an issue when OnClickOutside is continuously triggered when unneeded. StopPropagation mitigates that.

Usage

  1. Install nuget package.
  2. Add to the desired component/page or in _Imports.razor.
@using OutsideClickHandler.Component
  1. Add js src on index.html in wwwroot folder.
<script src="_content/OutsideClickHandler/outsideClickHandler.js"></script>
  1. That's it! You may now use it. Step3-1Step3-2

Parameters

  • OnOutsideClick
    • Accepts void function to be called on outside click.
    • Executed first when both OnOutsideClick and OnOutsideClickTask have value.
  • OnOutsideClickTask
    • Accepts awaitable function to be called on outside click.
  • StopPropagation
    • Stops OnOutsideClick and OnOutsideClickTask from executing when true.

About

Detect click outside of element for Blazor.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published