diff --git a/Components/CopyToClipboard.razor b/Components/CopyToClipboard.razor index 8dfc9ca..3d70047 100644 --- a/Components/CopyToClipboard.razor +++ b/Components/CopyToClipboard.razor @@ -1,8 +1,6 @@ @* -Copying to clipboard using a Blazor component with JSInterop as seen below does not work on iOS: -await _jsInterop.InvokeVoidAsync("navigator.clipboard.writeText", text); - -To work on iOS we are using JS code directly with the onclick function from an html input button. +The initial attempt to get CopyToClipboard working with Blazor JSInterop did not work on iOS. +So this component is using JS code directly with the onclick function from an html input button. *@ + try{ + navigator.clipboard.writeText('@TextToCopy'); + this.value='Password copied!' ; + setTimeout(()=> (this.value = 'Copy'), 2000); + } + catch (err) + { + alert (err); + } + "> @code { [Parameter] public string? TextToCopy { get; set; } diff --git a/Program.cs b/Program.cs index 10869aa..9827209 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,5 @@ using MudBlazor.Services; using passgen.Components; -using passgen.Services; var builder = WebApplication.CreateBuilder(args); @@ -9,8 +8,6 @@ builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); -builder.Services.AddScoped(); - builder.Services.AddMudServices(); var app = builder.Build(); diff --git a/Services/ClipboardService.cs b/Services/ClipboardService.cs deleted file mode 100644 index d6b32a7..0000000 --- a/Services/ClipboardService.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.JSInterop; - -namespace passgen.Services -{ - public class ClipboardService : IClipboardService - { - private readonly IJSRuntime _jsInterop; - - public ClipboardService(IJSRuntime jsInterop) - { - _jsInterop = jsInterop; - } - - public async Task CopyToClipboard(string text) - { - await _jsInterop.InvokeVoidAsync("navigator.clipboard.writeText", text); - } - } -} diff --git a/Services/IClipboardService.cs b/Services/IClipboardService.cs deleted file mode 100644 index 6a537bf..0000000 --- a/Services/IClipboardService.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace passgen.Services -{ - public interface IClipboardService - { - Task CopyToClipboard(string text); - } -}