Skip to content

Commit

Permalink
#565 Add BlurAttribute trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
YevgeniyShunevych committed Oct 21, 2021
1 parent 5f0594e commit 8131db5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Atata/Attributes/Triggers/BlurAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;

namespace Atata
{
/// <summary>
/// Indicates that the control blurring (removing focus) should be performed on the specified event.
/// By default occurs after set.
/// </summary>
public class BlurAttribute : TriggerAttribute
{
public BlurAttribute(
TriggerEvents on = TriggerEvents.AfterSet,
TriggerPriority priority = TriggerPriority.Medium)
: base(on, priority)
{
}

protected internal override void Execute<TOwner>(TriggerContext<TOwner> context)
{
if (context.Component is Control<TOwner> componentAsControl)
{
if (context.Event != TriggerEvents.BeforeBlur && context.Event != TriggerEvents.AfterBlur)
componentAsControl.Blur();
}
else
{
throw new InvalidOperationException($"{nameof(BlurAttribute)} trigger can be executed only against control. But was: {context.Component.GetType().FullName}.");
}
}
}
}

0 comments on commit 8131db5

Please sign in to comment.