Skip to content

Commit

Permalink
IOS fix attempt 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
onerdy committed Mar 4, 2024
1 parent 7ef2f18 commit 4839b32
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
19 changes: 19 additions & 0 deletions Components/CopyButton.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<a href=""
onclick="var el = this;
navigator.clipboard.writeText('@Value');"

>

<MudIcon Icon="@Icons.Material.Filled.ContentCopy" />

</a>

@code {
[Parameter] public string? Value { get; set; }

//onclick description:
//assign the anchor element to a variable since settimeout callback function loses the reference to "this"
//add a class to give IU feedback to the user hidding the standard copy icon and showing a loader
//write the value to clipboard. Due to IOS restrictions, Html native onclick event must be used instead of Blazor event.
//add a delay in miliseconds with a callback function that removes the CSS class to hide the loader and display the standard copy icon again
}
15 changes: 15 additions & 0 deletions Components/CopyButton.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.StandBy {
display: inline-block;
}

.Loader {
display: none;
}

.Copying .StandBy {
display: none;
}

.Copying .Loader {
display: inline-block;
}
7 changes: 5 additions & 2 deletions Components/CopyToClipboard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

<MudSnackbarProvider />

@* <MudIconButton OnClick="OnClick" Icon="@Icons.Material.Filled.ContentCopy" Size="Size.Small" /> *@
<button onclick="@OnClick" style="background-color:lightgray; padding:5px;border-radius: 4px;">Copy</button>
<MudIconButton OnClick="OnClick" Icon="@Icons.Material.Filled.ContentCopy" Size="Size.Small" />

@code {

Expand All @@ -25,11 +24,15 @@
try
{
await ClipboardService.CopyToClipboard(TextToCopy);

Snackbar.Add("Password copied!", Severity.Success);
}

catch(Exception e)
{
Snackbar.Configuration.ShowCloseIcon = true;
Snackbar.Configuration.RequireInteraction = true;

Snackbar.Add(e.Message, Severity.Error);
}

Expand Down
3 changes: 2 additions & 1 deletion Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
</MudField>
<MudStack Row="true">
<MudSpacer/>
<CopyToClipboard TextToCopy="@pass" />
@* <CopyToClipboard TextToCopy="@pass" /> *@
<CopyButton Value="@pass"/>
</MudStack>
</MudStack>
</MudCardContent>
Expand Down

0 comments on commit 4839b32

Please sign in to comment.