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

Fix #1205 FluentButton submit does not work outside the EditForm #v3 #1225

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 0 additions & 3 deletions Microsoft.FluentUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "Microsoft.FluentUI.AspNetCore.Components.Assets", "src\Core.Assets\Microsoft.FluentUI.AspNetCore.Components.Assets.esproj", "{292081C2-5076-467C-AEFF-12DC0617531A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TemplateValidation", "TemplateValidation", "{C2BD02DF-9FF9-4D0C-915E-EA1BD11585A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -141,7 +139,6 @@ Global
{17F26C55-E329-4117-B64D-0393E912FFFE} = {9468ADD1-3660-410D-8231-6F89384D135D}
{E4E62EAA-38FC-48FE-B63E-EB4ABAD660D2} = {17F26C55-E329-4117-B64D-0393E912FFFE}
{292081C2-5076-467C-AEFF-12DC0617531A} = {DF88C07D-46D7-4DEC-ACE4-409217634E57}
{C2BD02DF-9FF9-4D0C-915E-EA1BD11585A8} = {EBE3ACB2-9B23-4F91-9953-7153E3D2B0DA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {420693A7-C2FD-498C-8E78-4B65CC25389A}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,12 @@
Gets or sets the content to be rendered inside the component.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentButton.JSRuntime">
<summary />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentButton.Module">
<summary />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentButton.Autofocus">
<summary>
Determines if the element should receive document focus on page load.
Expand Down Expand Up @@ -704,6 +710,9 @@
Command executed when the user clicks on the button.
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentButton.OnAfterRenderAsync(System.Boolean)">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentButton.#ctor">
<summary>
Constructs an instance of <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentButton"/>.
Expand Down
37 changes: 33 additions & 4 deletions src/Core/Components/Button/FluentButton.razor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.FluentUI.AspNetCore.Components.Utilities;
using Microsoft.JSInterop;

namespace Microsoft.FluentUI.AspNetCore.Components;
public partial class FluentButton : FluentComponentBase
public partial class FluentButton : FluentComponentBase, IAsyncDisposable
{

private const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Button/FluentButton.razor.js";

private readonly string _customId = Identifier.NewId();
private readonly RenderFragment _renderButton;

/// <summary />
[Inject]
private IJSRuntime JSRuntime { get; set; } = default!;

/// <summary />
private IJSObjectReference? Module { get; set; }

private bool LoadingOverlay => Loading && IconStart == null && IconEnd == null;

/// <summary>
Expand Down Expand Up @@ -165,6 +176,16 @@ protected override void OnParametersSet()
}
}

/// <summary />
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && Id is not null)
{
Module ??= await JSRuntime.InvokeAsync<IJSObjectReference>("import", JAVASCRIPT_FILE);
await Module.InvokeVoidAsync("updateProxy", Id);
}
}

private string? CustomId =>
string.IsNullOrEmpty(BackgroundColor) && string.IsNullOrEmpty(Color) ? null : _customId;

Expand All @@ -188,14 +209,14 @@ public FluentButton()
}

/// <summary />
protected Task OnClickHandlerAsync(MouseEventArgs e)
protected async Task OnClickHandlerAsync(MouseEventArgs e)
{
if (!Disabled && OnClick.HasDelegate)
{
return OnClick.InvokeAsync(e);
await OnClick.InvokeAsync(e);
}

return Task.CompletedTask;
await Task.CompletedTask;
}

public void SetDisabled(bool disabled)
Expand All @@ -211,4 +232,12 @@ private string RingStyle(Icon icon)

return $"width: {size}px; height: {size}px;{inverse}";
}
public ValueTask DisposeAsync()
{
if (Module is not null)
{
return Module.DisposeAsync();
}
return ValueTask.CompletedTask;
}
}
11 changes: 11 additions & 0 deletions src/Core/Components/Button/FluentButton.razor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// workaround for https://github.com/microsoft/fast/issues/5675
export function updateProxy(id) {
if (!id) {
return;
}
const element = document.getElementById(id);

if (!!element && !!element.form) {
element.proxy.setAttribute("form", element.form.id)
}
}
11 changes: 10 additions & 1 deletion src/Core/Components/Slider/FluentSliderLabel.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Microsoft.FluentUI.AspNetCore.Components;

public partial class FluentSliderLabel<TValue> : FluentComponentBase
public partial class FluentSliderLabel<TValue> : FluentComponentBase, IAsyncDisposable
{
private const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/Slider/FluentSliderLabel.razor.js";

Expand Down Expand Up @@ -69,4 +69,13 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
await Module.InvokeVoidAsync("updateSliderLabel", Id);
}
}

public ValueTask DisposeAsync()
{
if (Module is not null)
{
return Module.DisposeAsync();
}
return ValueTask.CompletedTask;
}
}