Skip to content

Kebechet/Blazor.EventHandlers.LongPress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Blazor.EventHandlers.LongPress

This package contains @onlongpress event handler built from John Doherty's JS long-press

Motivation: For similar functionality you can also use oncontextmenu what is built-in event. But it doesnt work on iOS devices. Source

  • Before using the JS, I renamed triggered event name from long-press to longpress to be able to use it in Blazor.
  • I have also changed default show time from 1500ms to 400ms Based on android longpress implementation.
  • In case you would like to specify your custom time, you can do so by adding tag attribute with your custom time like:
<div @onlongpress="LongPressHandler" data-long-press-delay="100"> 

TIP: For better usage experience put: @using Blazor.EventHandlers.LongPress into _Imports.razor file.

TIP2 For combination with @onlongpress consider also use of @onshortclick

⚠️ Auto-initializers

  • In previous MAUI versions JS initializers were not working. So if you dont see text "Registering LongPress.js" in your JS console then you have to register this event handler manually in your index.html. At the end after blazor script put this:
<script defer src="_content/Kebechet.Blazor.EventHandlers.LongPress/LongPress.js"></script>
<script async>
	window.onload = function () {
		console.log("Registering LongPress.js");

		Blazor.registerCustomEventType('longpress', {
			createEventArgs: event => {
				return {
					bubbles: event.bubbles,
					cancelable: event.cancelable,
					screenX: event.detail.screenX,
					screenY: event.detail.screenY,
					clientX: event.detail.clientX,
					clientY: event.detail.clientY,
					offsetX: event.detail.offsetX,
					offsetY: event.detail.offsetY,
					pageX: event.detail.pageX,
					pageY: event.detail.pageY,
					sourceElement: event.srcElement.localName,
					targetElement: event.target.localName,
					timeStamp: event.timeStamp,
					type: event.type,
				};
			}
		});
	};
</script>
  • and then it should work as expected

Used resources

License

This repository is licensed with the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published