-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dev-v5] Add FluentSwitch component #3434
base: dev-v5
Are you sure you want to change the base?
Conversation
Note: The LabelPosition example has a strange behaviour : The switches bound to the same value lose their synchronization, depending on which one is clicked. Enregistrement.2025-02-23.154548.mp4 |
Indeed. You need to find why. 😀 |
Last "detail", in the PR description, can you include a summary of the component documentation (e.g. this PR #3267)? |
examples/Demo/FluentUI.Demo.Client/Documentation/Components/Switch/FluentSwitch.md
Show resolved
Hide resolved
...ples/Demo/FluentUI.Demo.Client/Documentation/Components/Switch/Examples/SwitchDisabled.razor
Show resolved
Hide resolved
…nentElementBase and Element
…alAttributes to set the field as readonly
tests/Core/Components/Switch/FluentSwitchTests.FluentCheckbox_ReadOnly.verified.razor.html
Outdated
Show resolved
Hide resolved
… (but "pointer-events: none" has no effect), tabindex, tests
Same behaviour with 3 Checkboxes bound to @value1 (Only two components are enough to show this de-synchronization effect). The html of all components is corresponding to the state of the |
[Obsolete] properties added in partial class and FluentSwitch added to Migration. I could use something like this in the field for the Label: |
@@ -0,0 +1,3 @@ | |||
fluent-switch[readonly] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked that the ReadOnly parameter blocks the use of the mouse and keyboard?
I think you need to apply this CSS style (on the “field” element and not on the “switch” element):
fluent-field:has(fluent-switch[readonly]) {
pointer-events: none;
}
And to block the keyboard, you need to set the tabindex
on the fluent-switch
(like done) but also on the FluentField
component. If not, using Tab
the user can navigate to the component and press Space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, css added for readonly and tabIndex on FluentField.
--- | ||
|
||
### Removed values💥 | ||
The `ChildContent` property has been removed. Use `FluentField` instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you replace with
The
ChildContent
property has been removed. UseLabel
parameter instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, documentation for migration updated.
@attributes="AdditionalAttributes" | ||
@onchange="@OnSwitchChangedHandler" | ||
slot="input" | ||
tabindex="@GetTabIndexValue" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few days ago, we added a new GetValueIfNoAdditionalAttribute
extension method to simplify this “feature”. Can you use code like this?
tabindex="@AdditionalAttributes.GetValueIfNoAdditionalAttribute("tabindex", "-1", when: () => ReadOnly)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, AdditionalAttributes.GetValueIfNoAdditionalAttribute
used for tabindex
.
src/Core/Migration/FluentSwitch.cs
Outdated
/// Gets or sets the checked message | ||
/// </summary> | ||
[Parameter] | ||
//[Obsolete("This property is not supported anymore and will be removed in a future release.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you uncomment these Obsolete
attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is an [Obsolete]
, it doesn't compile anymore, with this message:
'FluentSwitch.UncheckedMessage' is obsolete: 'This property is not supported anymore and will be removed in a future release.'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add a pragma
condition. We already used this in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thank you, Obsolete
uncommented.
|
||
@code | ||
{ | ||
public FluentSwitchTests() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Obsolete attributes (ChildContent, CheckedMessage and UncheckedMessage) must be unit tested.
You can run the file _StartCodeCoverage.cmd
to validate if all code lines a covered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, Tests added for ChildContent, CheckedMessage and UncheckedMessage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More tests added and _StartCodeCoverage.cmd
run. 100% on branch coverage and a bit like FluentCheckBox
on Line coverage.
} | ||
|
||
[Fact] | ||
public void FluentCheckbox_LabelPosition() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test can be omitted: you'll already be testing this position on the next next.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, FluentCheckbox_LabelPosition
single test removed.
} | ||
|
||
[Fact] | ||
public void FluentCheckbox_LabelTemplate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't test the LabelTemplate
but the Label
parameter.
(but this test in already include in FluentField tests)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, FluentCheckbox_LabelTemplate
Test done properly.
[dev-v5] Add FluentSwitch component
A FluentSwitch component represents a physical switch that allows someone to choose between two mutually exclusive options.
For example, "On/Off" and "Show/Hide". Choosing an option should produce an immediate result.
Best practices
Layout
When people need to perform extra steps for changes to take effect, use a check box instead. For example, if they must click a "Submit", "Next", or "OK" button to apply changes, use a check box.
Content
Only replace the On/Off labels if there are more specific labels for the setting. For example, you might use Show/Hide if the setting is "Show images".
Keep descriptive text short and concise—two to four words; preferably nouns. For example, "Focused inbox" or "WiFi".