Skip to content

[dev-v5] Add FluentField component - #3267

Merged
Denis Voituron (dvoituron) merged 32 commits into
dev-v5from
users/dvoituron/dev-v5/fluent-field
Feb 8, 2025
Merged

Denis Voituron (dvoituron) merged 32 commits into
dev-v5from
users/dvoituron/dev-v5/fluent-field

Conversation

@dvoituron

@dvoituron Denis Voituron (dvoituron) commented Jan 29, 2025 •

Copy link
Copy Markdown
Collaborator

[dev-v5] Add FluentField component

Field adds a label, validation message, and hint text to a control.

⚠️This component will be used with all Fluent Input components.

Label

The Label associated with the field.
This text is usually displayed above the component to describe it to the user.
You can position it on the left or right using LabelPosition.
In this case, the attribute LabelWidth can be used to set an identical label width
to multiple FluentField.

This label can be fully customized (bold, italic, icons, ...) using LabelTemplate.

Validation Message

The Message is used to give the user feedback about the value entered.
The field can validate itself using the rules defined in MessageCondition.
It can be used to signal the result of form validation.

This message can be fully customized (bold, italic, icons, ...) using MessageTemplate.

The MessageState affects the behavior and appearance of the message:

  • Error - The validation message has the red text An error occured with a red error icon.
  • Success - The validation message has gray text Valid data with a green checkmark icon.
  • Warning - The validation message has gray text Please, check this value with a yellow exclamation icon.
  • <null> - The validation message must be defined using Message or MessageTemplate.

These default messages can be located using the localization service.

Optionally, Message and MessageIcon attributes can be used to override
the default text and icon (or add an icon in the case of MessageState = null).

Message Conditions

The MessageCondition attribute specifies when to display the message
at the bottom of the FluentField.
This condition is a lambda expression (or method) whose input parameter
is the current IFluentField and output is true to display the message
or false to hide the message.

Examples: @(field => field.FocusLost == true) will display the message
when the user will leave the component.

To help you implement these rules, you can use the IFluentField.Where
method associated with the Display method. You must finalize the rule
definition using the method Build() (to start the validation of the rules).

Rules are evaluated in order of creation: the first rule checked applies
the associated Display action

field => field.When(() => MyValue.Length <= 1)
                   .Display("Less than 1", MessageState.Success)
              .When(() => MyValue.Length <= 3)
                   .Display("Less than 3", MessageState.Error)
              .When(() => MyValue.Length <= 5)
                   .Display("Less than 5", new Icons.Regular.Size16.Image())
              .When(() => true)
                   .Display(MessageState.Warning)
              .Build())

Usage in other Input components

Example for the FluentTextInput:

<FluentField InputComponent="@this" ForId="@Id" Class="@ClassValue" Style="@StyleValue">
    <fluent-text-input ... />
</FluentField>

Using InputComponent=‘@this’ allows the FluentField to retrieve all the parameters of IFluentField, like
Label, LabelTemplate, LabelPosition, LabelWidth, Required, Disabled, Message, MessageIcon, MessageTemplate, and MessageCondition.

peek_4

Examples

See the documentation and live samples: https://fluentui-blazor-v5.azurewebsites.net/Field

Unit Tests

image

@github-actions

github-actions Bot commented Jan 29, 2025 •

Copy link
Copy Markdown

✅ All tests passed successfully

Details on your Workflow / Core Tests page.

@github-actions

github-actions Bot commented Jan 29, 2025 •

Copy link
Copy Markdown

Summary - Unit Tests Code Coverage

Summary
Generated on: 02/08/2025 - 16:35:09
Coverage date: 02/08/2025 - 16:35:04
Parser: Cobertura
Assemblies: 1
Classes: 67
Files: 77
Line coverage: 99.1% (1454 of 1467)
Covered lines: 1454
Uncovered lines: 13
Coverable lines: 1467
Total lines: 6258
Branch coverage: 92% (896 of 973)
Covered branches: 896
Total branches: 973
Method coverage: Feature is only available for sponsors
Tag: 2572_13217419490

Coverage

Microsoft.FluentUI.AspNetCore.Components - 99.1%
Name Line Branch
Microsoft.FluentUI.AspNetCore.Components 99.1% 92%
Microsoft.FluentUI.AspNetCore.Components.DefaultStyles 100%
Microsoft.FluentUI.AspNetCore.Components.Dialog.MessageBox.FluentMessageBox 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogEventArgs 100% 92.8%
Microsoft.FluentUI.AspNetCore.Components.DialogInstance 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogOptions 100%
Microsoft.FluentUI.AspNetCore.Components.DialogOptionsFooter 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogOptionsFooterAction 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogOptionsHeader 100%
Microsoft.FluentUI.AspNetCore.Components.DialogResult 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogResult`1 100%
Microsoft.FluentUI.AspNetCore.Components.DialogService 98.9% 81.4%
Microsoft.FluentUI.AspNetCore.Components.DialogToggleEventArgs 100%
Microsoft.FluentUI.AspNetCore.Components.Extensions.EnumExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Extensions.FluentInputExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentButton 100% 89.5%
Microsoft.FluentUI.AspNetCore.Components.FluentComponentBase 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentDialog 97.4% 89.7%
Microsoft.FluentUI.AspNetCore.Components.FluentDialogBody 100% 91.6%
Microsoft.FluentUI.AspNetCore.Components.FluentDialogInstance 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentDialogProvider 100% 79.1%
Microsoft.FluentUI.AspNetCore.Components.FluentField 100% 96.4%
Microsoft.FluentUI.AspNetCore.Components.FluentFieldCondition 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentFieldConditionItem 100%
Microsoft.FluentUI.AspNetCore.Components.FluentFieldConditionOptions 100%
Microsoft.FluentUI.AspNetCore.Components.FluentFieldExtensions 100%
Microsoft.FluentUI.AspNetCore.Components.FluentFieldParameterSelector 100% 98.7%
Microsoft.FluentUI.AspNetCore.Components.FluentGrid 100% 90%
Microsoft.FluentUI.AspNetCore.Components.FluentGridItem 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentIcon`1 100% 95.8%
Microsoft.FluentUI.AspNetCore.Components.FluentInputBase`1 93.3% 25%
Microsoft.FluentUI.AspNetCore.Components.FluentInputImmediateBase`1 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentJSModule 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLabel 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLayout 100% 71.4%
Microsoft.FluentUI.AspNetCore.Components.FluentLayoutHamburger 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLayoutItem 100% 89.2%
Microsoft.FluentUI.AspNetCore.Components.FluentListBase`1 93.7% 94.7%
Microsoft.FluentUI.AspNetCore.Components.FluentLocalizerExtensions 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLocalizerInternal 100%
Microsoft.FluentUI.AspNetCore.Components.FluentOption 91.6% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentSelect`1 100%
Microsoft.FluentUI.AspNetCore.Components.FluentServiceBase`1 100%
Microsoft.FluentUI.AspNetCore.Components.FluentServiceProviderException`1 100%
Microsoft.FluentUI.AspNetCore.Components.FluentStack 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentStatus 100%
Microsoft.FluentUI.AspNetCore.Components.FluentText 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentTextInput 100% 78.5%
Microsoft.FluentUI.AspNetCore.Components.Icon 100% 91.1%
Microsoft.FluentUI.AspNetCore.Components.IconFromImage 100%
Microsoft.FluentUI.AspNetCore.Components.IconInfo 100%
Microsoft.FluentUI.AspNetCore.Components.IFluentLocalizer 100% 100%
Microsoft.FluentUI.AspNetCore.Components.InternalListContext`1 60%
Microsoft.FluentUI.AspNetCore.Components.Localization.LanguageResource 100% 100%
Microsoft.FluentUI.AspNetCore.Components.MessageBoxOptions 100%
Microsoft.FluentUI.AspNetCore.Components.Migration.AppearanceExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Migration.FluentInputAppearanceExt
ensions
100% 100%
Microsoft.FluentUI.AspNetCore.Components.ServiceProviderExtensions 100%
Microsoft.FluentUI.AspNetCore.Components.SpacingExtensions 100% 97.2%
Microsoft.FluentUI.AspNetCore.Components.Utilities.AddTag 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.CssBuilder 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.Debounce 100% 83.3%
Microsoft.FluentUI.AspNetCore.Components.Utilities.Identifier 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.IdentifierContext 100% 75%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InlineStyleBuilder 100% 92.8%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InternalDebounce.Dispatc
herTimerExtensions
95.7% 75%
Microsoft.FluentUI.AspNetCore.Components.Utilities.StyleBuilder 100% 100%
Microsoft.FluentUI.AspNetCore.Components.ZIndex 100%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants