Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced cursor change based on allow panning. #20

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Blazor.Diagrams/Components/DiagramCanvas.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="diagram-canvas @Class"
tabindex="-1"
style="@Style"
@ref="elementReference"
@onpointerdown="OnPointerDown"
@onpointermove="OnPointerMove"
Expand Down
2 changes: 2 additions & 0 deletions src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public partial class DiagramCanvas : IDisposable
{
private DotNetObjectReference<DiagramCanvas>? _reference;
private bool _shouldRender;
private string? Style;

protected ElementReference elementReference;

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/Blazor.Diagrams/wwwroot/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions tests/Blazor.Diagrams.Tests/Components/DiagramCursorTests.cs
Original file line number Diff line number Diff line change
@@ -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<Rectangle>("ZBlazorDiagrams.getBoundingClientRect", _ => true);

// Act
var cut = ctx.RenderComponent<DiagramCanvas>(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<Rectangle>("ZBlazorDiagrams.getBoundingClientRect", _ => true);

// Act
var cut = ctx.RenderComponent<DiagramCanvas>(parameters => parameters
.Add(n => n.BlazorDiagram, diagram));
var diagramCanvas = cut.Find(".diagram-canvas");
var canvasStyle = diagramCanvas.GetStyle().CssText;

// Assert
canvasStyle.Should().Contain("cursor: default");
}
}
}
Loading