diff --git a/site/Site/Pages/Documentation/Controls/Overview.razor b/site/Site/Pages/Documentation/Controls/Overview.razor index bd87fa9a..70c6a1f2 100644 --- a/site/Site/Pages/Documentation/Controls/Overview.razor +++ b/site/Site/Pages/Documentation/Controls/Overview.razor @@ -39,6 +39,7 @@ // Initialize var node1Controls = Diagram.Controls.AddFor(Node1); // OnSelection default var node2Controls = Diagram.Controls.AddFor(Node2, ControlsType.OnHover); +var node3Controls = Diagram.Controls.AddFor(Node2, ControlsType.AlwaysOn); // Control always visible // Add node1Controls.Add(new SomeControl()); diff --git a/src/Blazor.Diagrams.Core/Controls/ControlsContainer.cs b/src/Blazor.Diagrams.Core/Controls/ControlsContainer.cs index 5ebc16b4..1a71d1d0 100644 --- a/src/Blazor.Diagrams.Core/Controls/ControlsContainer.cs +++ b/src/Blazor.Diagrams.Core/Controls/ControlsContainer.cs @@ -16,6 +16,10 @@ public ControlsContainer(Model model, ControlsType type = ControlsType.OnSelecti { Model = model; Type = type; + if (type == ControlsType.AlwaysOn) + { + Visible = true; + } } public Model Model { get; } diff --git a/src/Blazor.Diagrams.Core/Controls/ControlsType.cs b/src/Blazor.Diagrams.Core/Controls/ControlsType.cs index 5997e72c..641a79fd 100644 --- a/src/Blazor.Diagrams.Core/Controls/ControlsType.cs +++ b/src/Blazor.Diagrams.Core/Controls/ControlsType.cs @@ -3,5 +3,6 @@ namespace Blazor.Diagrams.Core.Controls; public enum ControlsType { OnHover, - OnSelection + OnSelection, + AlwaysOn } \ No newline at end of file diff --git a/tests/Blazor.Diagrams.Core.Tests/Controls/ControlsContainerTests.cs b/tests/Blazor.Diagrams.Core.Tests/Controls/ControlsContainerTests.cs new file mode 100644 index 00000000..3b36ebd1 --- /dev/null +++ b/tests/Blazor.Diagrams.Core.Tests/Controls/ControlsContainerTests.cs @@ -0,0 +1,28 @@ +using Blazor.Diagrams.Core.Controls; +using Blazor.Diagrams.Core.Events; +using Blazor.Diagrams.Core.Models; +using Xunit; + +namespace Blazor.Diagrams.Core.Tests.Controls +{ + public class ControlsContainerTests + { + [Fact] + public void AlwaysOnControlType_AlwaysVisible() + { + // Arrange + var diagram = new TestDiagram(); + var node = diagram.Nodes.Add(new NodeModel()); + var controls = diagram.Controls.AddFor(node, ControlsType.AlwaysOn); + + // Assert + Assert.True(controls.Visible); + + node.Selected = true; + Assert.True(controls.Visible); + + diagram.TriggerPointerEnter(node, new PointerEventArgs(0, 0, 0, 0, false, false, false, 0, 0, 0, 0, 0, 0, string.Empty, true)); + Assert.True(controls.Visible); + } + } +} \ No newline at end of file