diff --git a/src/Blazor.Diagrams/Components/DiagramCanvas.razor b/src/Blazor.Diagrams/Components/DiagramCanvas.razor
index 76905844..a5ad2f36 100644
--- a/src/Blazor.Diagrams/Components/DiagramCanvas.razor
+++ b/src/Blazor.Diagrams/Components/DiagramCanvas.razor
@@ -1,5 +1,6 @@
? _reference;
private bool _shouldRender;
+ private string? Style;
protected ElementReference elementReference;
@@ -52,6 +53,7 @@ protected override void OnInitialized()
_reference = DotNetObjectReference.Create(this);
BlazorDiagram.Changed += OnDiagramChanged;
+ Style = BlazorDiagram.Options.AllowPanning ? "cursor: grab; cursor: -webkit-grab;" : "cursor: default;";
}
protected override async Task OnAfterRenderAsync(bool firstRender)
diff --git a/src/Blazor.Diagrams/wwwroot/style.css b/src/Blazor.Diagrams/wwwroot/style.css
index 35c0aaa3..6079a2d2 100644
--- a/src/Blazor.Diagrams/wwwroot/style.css
+++ b/src/Blazor.Diagrams/wwwroot/style.css
@@ -4,8 +4,6 @@
position: relative;
outline: none;
overflow: hidden;
- cursor: -webkit-grab;
- cursor: grab;
touch-action: none;
}
diff --git a/tests/Blazor.Diagrams.Tests/Components/DiagramCursorTests.cs b/tests/Blazor.Diagrams.Tests/Components/DiagramCursorTests.cs
new file mode 100644
index 00000000..ed6ad41e
--- /dev/null
+++ b/tests/Blazor.Diagrams.Tests/Components/DiagramCursorTests.cs
@@ -0,0 +1,49 @@
+using AngleSharp.Css.Dom;
+using Blazor.Diagrams.Components;
+using Blazor.Diagrams.Core.Geometry;
+using Bunit;
+using FluentAssertions;
+using Xunit;
+
+namespace Blazor.Diagrams.Core.Tests.Behaviors
+{
+ public class DiagramCursorTests
+ {
+ [Fact]
+ public void Behavior_WhenPanningOptionIsAllowed_CursorShouldBeGrab()
+ {
+ // Arrange
+ using var ctx = new TestContext();
+ var diagram = new BlazorDiagram();
+ diagram.Options.AllowPanning = true;
+ ctx.JSInterop.Setup("ZBlazorDiagrams.getBoundingClientRect", _ => true);
+
+ // Act
+ var cut = ctx.RenderComponent(parameters => parameters
+ .Add(n => n.BlazorDiagram, diagram));
+ var diagramCanvas = cut.Find(".diagram-canvas");
+
+ // Assert
+ diagramCanvas.ToMarkup().Should().Contain("cursor: grab; cursor: -webkit-grab;");
+ }
+
+ [Fact]
+ public void Behavior_WhenPanningOptionIsNotAllowed_CursorShouldBeDefault()
+ {
+ // Arrange
+ using var ctx = new TestContext();
+ var diagram = new BlazorDiagram();
+ diagram.Options.AllowPanning = false;
+ ctx.JSInterop.Setup("ZBlazorDiagrams.getBoundingClientRect", _ => true);
+
+ // Act
+ var cut = ctx.RenderComponent(parameters => parameters
+ .Add(n => n.BlazorDiagram, diagram));
+ var diagramCanvas = cut.Find(".diagram-canvas");
+ var canvasStyle = diagramCanvas.GetStyle().CssText;
+
+ // Assert
+ canvasStyle.Should().Contain("cursor: default");
+ }
+ }
+}