Skip to content

Commit

Permalink
enabled wheel preventing only for scroll behavior, other pr suggestio…
Browse files Browse the repository at this point in the history
…ns addressed
  • Loading branch information
shams-azam-wtg committed Jul 10, 2024
1 parent cfa5fec commit 3d0517e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 2 additions & 3 deletions site/Site/Pages/Documentation/Diagram/Behaviors.razor
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ You can use the following ways to add different behaviors to the diagram.

<h3>Scroll Behavior</h3>

<p>To scroll the diagram using the mouse wheel you can register the Scroll Behavior.</p>
<p>To scroll the diagram using the mouse wheel use ScrollBehavior.</p>

<pre><code class="language-cs">
Diagram.UnregisterBehavior&lt;WheelBehavior&gt;();
Diagram.RegisterBehavior(new ScrollBehavior(Diagram));
_diagram.BehaviorOptions.DiagramWheelBehavior = _diagram.GetBehavior&lt;ScrollBehavior&gt;();
</code></pre>


Expand Down
8 changes: 6 additions & 2 deletions src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Blazor.Diagrams.Core.Behaviors;
using Blazor.Diagrams.Core.Geometry;
using Blazor.Diagrams.Extensions;
using Microsoft.AspNetCore.Components;
Expand Down Expand Up @@ -64,7 +65,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
BlazorDiagram.SetContainer(await JSRuntime.GetBoundingClientRect(elementReference));
await JSRuntime.ObserveResizes(elementReference, _reference!);
await JSRuntime.AddDefaultPreventingHandler(elementReference);
if (BlazorDiagram.GetBehavior<ScrollBehavior>() != null)
{
await JSRuntime.AddDefaultPreventingForWheelHandler(elementReference);
}
}
}

Expand Down Expand Up @@ -102,7 +106,7 @@ private void OnKeyDown(KeyboardEventArgs e)
BlazorDiagram.TriggerKeyDown(e.ToCore());
}

private async void OnWheel(WheelEventArgs e)
private void OnWheel(WheelEventArgs e)
{
BlazorDiagram.TriggerWheel(e.ToCore());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blazor.Diagrams/Extensions/JSRuntimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static async Task UnobserveResizes(this IJSRuntime jsRuntime, ElementRefe
await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.unobserve", element, element.Id);
}

public static async Task AddDefaultPreventingHandler(this IJSRuntime jsRuntime, ElementReference element)
public static async Task AddDefaultPreventingForWheelHandler(this IJSRuntime jsRuntime, ElementReference element)
{
await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.addDefaultPreventingHandler", element, "wheel");
}
Expand Down

0 comments on commit 3d0517e

Please sign in to comment.