Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d04c34f
Add FluentField (Draft)
dvoituron Jan 28, 2025
08bd19b
Fix Style
dvoituron Jan 28, 2025
a4c6583
Refactoring FluentField
dvoituron Jan 29, 2025
b21a70c
Add MessageCondition
dvoituron Jan 29, 2025
bd2aeba
Add Localizer
dvoituron Jan 29, 2025
033f728
Merge branch 'dev-v5' into users/dvoituron/dev-v5/fluent-field
dvoituron Jan 29, 2025
f40e401
Refactor Class and Style
dvoituron Jan 29, 2025
3396b22
Fix Id
dvoituron Jan 29, 2025
6d69c40
Add DefaultStyles
dvoituron Jan 29, 2025
3a9587c
Fix Unit Tests and change a style to a class
dvoituron Jan 29, 2025
d4e6025
Refactoring
dvoituron Jan 30, 2025
b21be91
Add MessageState
dvoituron Jan 31, 2025
03e80ad
Add FluentMessageState
dvoituron Jan 31, 2025
f7edfac
Add FluentFieldConditions
dvoituron Jan 31, 2025
9ea74df
Update sample
dvoituron Jan 31, 2025
eba2f6c
Add FieldCondition When and Display
dvoituron Jan 31, 2025
33fc578
Add first part of the doc
dvoituron Feb 1, 2025
7b64ca4
Add update doc
dvoituron Feb 1, 2025
9f70205
Fix Condition
dvoituron Feb 1, 2025
52ff3cb
Update doc
dvoituron Feb 1, 2025
8546266
Fix Unit Tests
dvoituron Feb 1, 2025
2d2adb3
Update Global unit tests and fix some details
dvoituron Feb 4, 2025
285761f
Add unit tests
dvoituron Feb 4, 2025
74553b2
Add Unit Tests and rename enum LabelPosition and MessageState
dvoituron Feb 4, 2025
fc2dbd4
Add test for LostFocus
dvoituron Feb 4, 2025
35b23ec
Add Unit Test for LostFocus property
dvoituron Feb 4, 2025
198ed1e
Add Unit Tests
dvoituron Feb 5, 2025
3f3b694
Add Unit Tests for ParameterSelector
dvoituron Feb 5, 2025
c7be0c3
Add Unit Tests
dvoituron Feb 5, 2025
e6bb0d2
Add method comments
dvoituron Feb 5, 2025
01c0fcb
Add .Build(options => options.BreakOnFirst = false)
dvoituron Feb 5, 2025
1b99e2c
Add Unit Tests
dvoituron Feb 6, 2025
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: My Counter (Test)
category: 0200|Labs
category: 20|Labs
icon: Regular.ArrowBetweenUp
route: /Test/Counter
---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<FluentTextInput Label="Example field"
MessageState="MessageState.Success"
Message="This is a success message."
MessageCondition="@FluentFieldCondition.Always" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<FluentStack Orientation="Orientation.Vertical">
<FluentField Label="Label above"
ForId="field-21"
Message="This is a success message"
MessageIcon="@FluentStatus.SuccessIcon">
<InputText id="field-21" @bind-Value="@Value1" />
</FluentField>

<FluentField Label="Label before"
LabelPosition="@LabelPosition.Before"
LabelWidth="150px"
ForId="field-22"
Required="true"
Message="This is an error message"
MessageIcon="@FluentStatus.ErrorIcon">
<fluent-text-input id="field-22" />
</FluentField>

<FluentField Label="Other label before"
LabelPosition="@LabelPosition.Before"
LabelWidth="150px"
ForId="field-23"
Required="true"
Message="This is an info message"
MessageIcon="@FluentStatus.InfoIcon">
<fluent-text-input id="field-23" />
</FluentField>

<FluentField Label="Label after"
LabelPosition="@LabelPosition.After"
ForId="field-24"
Message="This is a warning message"
MessageIcon="@FluentStatus.WarningIcon">
<fluent-text-input id="field-24" />
</FluentField>

<FluentField>
<fluent-text-input />
</FluentField>

<FluentField Label="Label above"
Message="This is a success message"
MessageIcon="@FluentStatus.SuccessIcon">
TOTO
</FluentField>

<FluentField Label="Label above"
Message="This is a success message"
MessageIcon="@FluentStatus.SuccessIcon">
<select>
<option>One</option>
<option>Two</option>
</select>
</FluentField>

<FluentTextInput Label="My label" MessageState="@MessageState.Error" MessageCondition="@(i => true)" />

<FluentTextInput Label="My label 4"
@bind-Value="@Value4"
Immediate="true"
MessageCondition="@(i => i.When(() => Value4.Length > 7).Display(MessageState.Warning)
.When(() => Value4.Length > 5).Display("More than 5", new Icons.Regular.Size16.Image())
.When(() => Value4.Length > 3).Display("More than 3", MessageState.Error)
.When(() => Value4.Length > 1).Display("More than 1", MessageState.Success)
.Build())" />

<FluentTextInput id="myText" Label="@LabelSample" Required="true" Margin="30px" MessageCondition="DisplayMessage" @bind-Value="@Value2" Immediate="true" />
<FluentButton OnClick="@(e => LabelSample = LabelSample + "x")">Click</FluentButton>


<FluentTextInput id="myText2" Label="@LabelSample" LabelPosition="LabelPosition.Before" Required="true" Margin="30px" @bind-Value="@Value3" Immediate="true" />

</FluentStack>

@code
{
string Value4 = "";

string LabelSample = "Label sample";
string Value1 = "";
string Value2 = "";
string Value3 = "";

bool DisplayMessage(IFluentField input)
{
// if (input.FocusLost == false)
// {
// return false;
// }

if (Value2.Length == 0)
{
input.Message = "My custom required message";
input.MessageState = MessageState.Error;
return true;
}

if (Value2.Length >= 1 && Value2.Length <= 3)
{
input.Message = null;
input.MessageTemplate = null;
input.MessageState = null;
}

if (Value2.Length > 3)
{
input.MessageState = MessageState.Warning;
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<FluentSelect Label="Position"
Items="@GetLabelPositions()"
@bind-Value="@SelectedPosition" />

<FluentStack Orientation="Orientation.Vertical">

<FluentField Label="My first label:" LabelWidth="150px" LabelPosition="@SelectedPosition">
<FluentTextInput />
</FluentField>

<FluentField LabelWidth="150px" LabelPosition="@SelectedPosition" Required="true">
<LabelTemplate>
My&nbsp;<b>second</b>&nbsp;<i>label</i>:
</LabelTemplate>
<ChildContent>
<FluentTextInput />
</ChildContent>
</FluentField>

</FluentStack>

@code
{
private LabelPosition SelectedPosition;

public static IEnumerable<LabelPosition> GetLabelPositions()
{
return Enum.GetValues(typeof(LabelPosition)).Cast<LabelPosition>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<FluentTextInput Label="Example field"
Placeholder="Type some characters"
@bind-Value="@MyValue"
Immediate="true"
MessageCondition="@(i => i.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())" />

@code
{
string MyValue = "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<FluentTextInput Label="Example field"
TextFieldType="TextInputType.Password"
@bind-Value="@MyValue"
Immediate="true"
MessageCondition="@(i => i.When(() => MyValue.Length < 8)
.Display("8+ characters", MessageState.Error)
.When(() => MyValue.Any(char.IsDigit) == false)
.Display("Using number", MessageState.Error)
.When(() => MyValue.Any(char.IsUpper) == false)
.Display("Capital letters", MessageState.Error)
.When(() => MyValue.Any(char.IsLower) == false)
.Display("Lowercase letters", MessageState.Error)
.When(() => MyValue.Length >= 8 && MyValue.Any(char.IsDigit) && MyValue.Any(char.IsUpper) && MyValue.Any(char.IsLower))
.Display("Valid password", MessageState.Success)
.Build(options => options.BreakOnFirst = false))" />

@code
{
string MyValue = "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<FluentTextInput Label="Error state"
MessageState="@MessageState.Error"
Message="This is an error message."
MessageCondition="@FluentFieldCondition.Always" />

<FluentTextInput Label="Warning state"
MessageState="@MessageState.Warning"
Message="This is a warning message."
MessageCondition="@FluentFieldCondition.Always" />

<FluentTextInput Label="Success state"
MessageState="@MessageState.Success"
Message="This is a success message."
MessageCondition="@FluentFieldCondition.Always" />

<FluentTextInput Label="Custom state"
Message="This is a custom message."
MessageIcon="@(new Icons.Regular.Size24.Accessibility())"
MessageCondition="@FluentFieldCondition.Always" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
title: Field
route: /Field
---

# Field

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

{{ FieldDefault }}

## Best practices

**Do**

- Use Field to add a label and validation message to form controls.
- Use Field to label other unlabeled controls like ProgressBar.

**Don't**

- Avoid including both a validationMessage and hint text.
- Don't add multiple controls as a child of a single Field. The label is only associated with one control.
- Don't use the Field's label with Checkbox. Use the Checkbox's label instead (the Field can still be used to add a validationMessage or hint).

## 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`.

{{ FieldLabelExample }}

> By default, the `my-3` class is added to all `FluentField`
> that contain at least one `Label` or `Message`,
> to add `12px` before (top) and after (bottom) the field.
> This will automatically make all your form fields **24px** apart,
> as recommended by the FluentUI designers.
>
> This default value can be modified or removed globally via the startup options:
> `builder.Services.AddFluentUIComponents(options => options.DefaultStyles.FluentFieldClass = "my-class" );`

## 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](/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`).

{{ FieldStatesExample }}

⚠️ **Note** that the `MessageCondition` attribute must be set to
`(i) => true` or identical to `FluentFieldCondition.Always`.
This enables the message to be displayed, which is not the case by default.

## Input components

All **FluentUI Blazor** input components contains the same `FluentField` attributes:
like `Label`, `Message`, `MessageCondition`, `MessageState` and others.

You can use them directly from the Input component to influence the included `FLuentField`

## 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

```csharp
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())
```

{{ FieldMessageCondition }}

You can combine the conditions to display several messages simultaneously,
using an option in the `Build` method: `.Build(options => options.BreakOnFirst = false)`.

{{ FieldMessageMultipleConditions }}

## API FluentField

{{ API Type=FluentField }}
Loading