Skip to content
Open
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
24 changes: 24 additions & 0 deletions src/Core.Scripts/src/Components/TextInput/TextInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ export namespace Microsoft.FluentUI.Blazor.Components.TextInput {
}
};

export function setEdgePasswordRevealToggle(id: string, hide: boolean): void {
const fieldElement = document.getElementById(id);
const shadowRoot = fieldElement?.shadowRoot;

if (!shadowRoot) {
return;
}

const styleElement = shadowRoot.querySelector("style[data-fluent-text-field-edge-password-toggle]");

if (hide) {
if (!styleElement) {
const newStyleElement = document.createElement("style");
newStyleElement.setAttribute("data-fluent-text-field-edge-password-toggle", "true");
newStyleElement.textContent = "#control::-ms-reveal { display: none !important; }";
shadowRoot.appendChild(newStyleElement);
}

return;
}

styleElement?.remove();
}

/**
* Type for elements that support delayed 'immediate' input events
*/
Expand Down
27 changes: 26 additions & 1 deletion src/Core/Components/TextInput/FluentTextInput.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ public FluentTextInput(LibraryConfiguration configuration) : base(configuration)
/// Gets or sets a value indicating whether spellcheck should be used.
/// </summary>
[Parameter]
public bool? Spellcheck { get; set; } // TODO: To verify if this is supported by the component
public bool? Spellcheck { get; set; } // TODO: To verify if this is supported by the component

/// <summary>
/// Gets or sets a value indicating whether the Microsoft Edge password toggle should be hidden for password fields.
/// </summary>
[Parameter]
public bool HideEdgePasswordToggle { get; set; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this parameter is too specific to a particular browser. I need to look into this further to find a more general solution. Give me until next weekβ€”that way I'll have more time.


/// <summary>
/// Gets or sets the type of data that can be entered by the user when editing the element or its content.
Expand Down Expand Up @@ -202,6 +208,9 @@ protected override async Task OnInitializedAsync()
await base.RenderTooltipAsync(Tooltip);
}

/// <summary />
private bool _isEdgePasswordToggleHidden;

/// <inheritdoc cref="ComponentBase.OnAfterRenderAsync(bool)" />
protected override async Task OnAfterRenderAsync(bool firstRender)
{
Expand All @@ -223,6 +232,22 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
await JSRuntime.InvokeVoidAsync("Microsoft.FluentUI.Blazor.Components.TextMasked.applyPatternMask", Id, MaskPattern, MaskLazy, placeholder);
}
}

if (TextInputType == Components.TextInputType.Password)
{
await JSRuntime.InvokeVoidAsync(
"Microsoft.FluentUI.Blazor.Components.TextInput.setEdgePasswordRevealToggle",
Id, HideEdgePasswordToggle
);
}
else if (_isEdgePasswordToggleHidden)
{
_isEdgePasswordToggleHidden = false;
await JSRuntime.InvokeVoidAsync(
"Microsoft.FluentUI.Blazor.Components.TextInput.setEdgePasswordRevealToggle",
Id, false
);
}
}

/// <summary>
Expand Down
38 changes: 38 additions & 0 deletions tests/Core/Components/TextInput/FluentTextInputTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,44 @@
.MarkupMatches($"<fluent-text-input id=\"myId\" slot=\"input\" appearance=\"outline\" type=\"{expectedAttribute}\" />");
}

[Fact]
public void FluentInputText_HideEdgePasswordToggle_DoesNotAffectMarkup()
{
// Arrange
using var context = new IdentifierContext(i => "myId");
var invocation = JSInterop.SetupVoid(
"Microsoft.FluentUI.Blazor.Components.TextInput.setEdgePasswordRevealToggle",
_ => true);

// Act
var cut = Render(@<FluentTextInput TextInputType="@TextInputType.Password" HideEdgePasswordToggle="true" />);
cut.Find("fluent-text-input")
.MarkupMatches("<fluent-text-input id=\"myId\" slot=\"input\" appearance=\"outline\" type=\"password\" />");

var call = Assert.Single(invocation.Invocations);
Assert.Equal("myId", call.Arguments[0]);
Assert.Equal(true, call.Arguments[1]);
}

[Fact]
public void FluentInputText_HideEdgePasswordToggle_OnNonPasswordField_DoesNotAffectMarkup()
{
// Arrange
using var context = new IdentifierContext(i => "myId");
var invocation = JSInterop.SetupVoid(
"Microsoft.FluentUI.Blazor.Components.TextInput.setEdgePasswordRevealToggle",
_ => true);

// Act
var cut = Render(@<FluentTextInput TextInputType="@TextInputType.Text" HideEdgePasswordToggle="true" />);

// Assert
cut.Find("fluent-text-input")
.MarkupMatches("<fluent-text-input id=\"myId\" slot=\"input\" appearance=\"outline\" type=\"text\" />");

Assert.Empty(invocation.Invocations);
}

[Theory]
[InlineData(TextInputSize.Small)]
[InlineData(TextInputSize.Medium)]
Expand Down