Skip to content

Commit

Permalink
implement IsDisabled parameter for RadioGroupOption
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed Aug 22, 2024
1 parent 5d025ad commit 3faad53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/Ignis.Components/ComponentEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class ComponentEvent : IComponentEvent, IDisposable
{
private readonly CancellationTokenSource _cancellationTokenSource = new();

//TODO rename to IsDefaultPrevented

Check warning on line 7 in packages/Ignis.Components/ComponentEvent.cs

View workflow job for this annotation

GitHub Actions / Test

Check warning on line 7 in packages/Ignis.Components/ComponentEvent.cs

View workflow job for this annotation

GitHub Actions / Test

Check warning on line 7 in packages/Ignis.Components/ComponentEvent.cs

View workflow job for this annotation

GitHub Actions / Test

public bool DefaultPrevented => this._cancellationTokenSource.IsCancellationRequested;

public void PreventDefault()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace Ignis.Components.HeadlessUI.Aria;

/// <summary>
/// A component part which can be disabled.
/// A component which can be disabled.
/// </summary>
public interface IAriaDisabled
{
/// <summary>
/// Whether the component is disabled.
/// </summary>
bool IsDisabled { get; set; }
}
10 changes: 10 additions & 0 deletions packages/Tailwind/Ignis.Components.HeadlessUI/RadioGroupOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ protected override IEnumerable<object> Targets
/// <inheritdoc />
[Parameter]
public string? Id { get; set; }

/// <inheritdoc />
[Parameter] public bool IsDisabled { get; set; }

/// <inheritdoc />
[Parameter]
Expand Down Expand Up @@ -110,6 +113,7 @@ public RadioGroupOption()
() => new KeyValuePair<string, object?>("aria-checked", IsChecked.ToString().ToLowerInvariant()),
() => new KeyValuePair<string, object?>("aria-labelledby", RadioGroup.GetId(Label)),
() => new KeyValuePair<string, object?>("aria-describedby", RadioGroup.GetId(Description)),
() => new KeyValuePair<string, object?>("aria-disabled", IsDisabled.ToString().ToLowerInvariant()),
});
}

Expand Down Expand Up @@ -180,6 +184,8 @@ protected override void OnKeyDown(KeyboardEventArgs eventArgs)

public void Check()
{
if (IsDisabled) return;

RadioGroup.CheckValue(Value);

RadioGroup.ActiveOption = this;
Expand All @@ -201,12 +207,16 @@ private void Click()
/// <inheritdoc />
protected override void OnTargetFocus()
{
if (IsDisabled) return;

RadioGroup.ActiveOption = this;
}

/// <inheritdoc />
protected override void OnTargetBlur()
{
if (IsDisabled) return;

if (RadioGroup.ActiveOption == this) RadioGroup.ActiveOption = null;
}

Expand Down

0 comments on commit 3faad53

Please sign in to comment.