Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<FluentRating Max="5"
Label="Rate me!"
@bind-Value="@SelectedValue"
OnHoverValueChanged="@(i => HoverValue = i)" />
OnHoverValueChanged="@(i => HoverValue = i)"
AllowReset="true"/>
<FluentLabel>@LabelText</FluentLabel>
</FluentStack>

Expand Down
3 changes: 2 additions & 1 deletion src/Core/Components/Rating/FluentRating.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
{
<input type="radio" checked="@(index == Value)" name="@GroupName"
value="@index"
@onfocus="@(() => OnClickAsync(index, fromFocus: true))" />
@onfocus="@(() => OnClickAsync(index, fromFocus: true))"
@onkeydown="@OnKeyDownAsync" />

<FluentIcon Value="@GetIcon(index)"
Width="@IconWidth"
Expand Down
18 changes: 16 additions & 2 deletions src/Core/Components/Rating/FluentRating.razor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components.Utilities;
// ------------------------------------------------------------------------
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.FluentUI.AspNetCore.Components.Utilities;

namespace Microsoft.FluentUI.AspNetCore.Components;

Expand Down Expand Up @@ -109,6 +114,15 @@ private async Task OnClickAsync(int value, bool fromFocus = false)
}
}

private async Task OnKeyDownAsync(KeyboardEventArgs args)
{
if (AllowReset && args.Key == " ")
{
await SetCurrentValueAsync(0);
await UpdateHoverValueAsync(null);
}
}

/// <summary />
private async Task OnMouseEnterAsync(int value)
{
Expand Down
Loading