Skip to content
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

MudSlider: Add nullable value parameter #8881

Merged
merged 8 commits into from
May 6, 2024

Conversation

ScarletKuro
Copy link
Member

Description

Fixes: #8860 (comment)

nullable

How Has This Been Tested?

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added enhancement New feature or request PR: needs review labels May 5, 2024
@ScarletKuro
Copy link
Member Author

@henon @danielchalmers is this good enough?

@ScarletKuro ScarletKuro marked this pull request as draft May 5, 2024 10:31
@ScarletKuro ScarletKuro marked this pull request as ready for review May 5, 2024 11:05
Copy link

codecov bot commented May 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.22%. Comparing base (28bc599) to head (f14a0d4).
Report is 152 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8881      +/-   ##
==========================================
+ Coverage   89.82%   90.22%   +0.39%     
==========================================
  Files         412      424      +12     
  Lines       11878    12286     +408     
  Branches     2364     2406      +42     
==========================================
+ Hits        10670    11085     +415     
+ Misses        681      669      -12     
- Partials      527      532       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@henon henon left a comment

Choose a reason for hiding this comment

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

I guess that resolves it just fine. In the example a Button to reset the nullable value to null would be awesome.

@henon henon added breaking change API change API that needs approval v7 New major MudBlazor version and removed PR: needs review labels May 5, 2024
@henon henon mentioned this pull request May 5, 2024
@henon
Copy link
Collaborator

henon commented May 5, 2024

Added to v7.0.0 Migration Guide #8447

@ScarletKuro
Copy link
Member Author

ScarletKuro commented May 5, 2024

Updated example
nullable

There is another breaking change:
RenderFragment<T> -> RenderFragment<SliderContext<T>> as we now need both values..

@ScarletKuro
Copy link
Member Author

I will add explicit bUnit test if @danielchalmers approves this approach.

@ScarletKuro
Copy link
Member Author

ScarletKuro commented May 5, 2024

The alert is not relevant anymore in the example. Added trick that it will work when you two way bind two values.

I noticed that now when the knob is in the begging and since it stays at zero, if you touch the knob but not move it the value update will not trigger means the nullabeValue will also stay null. I don't think i can force input to trigger the binding when value actually didn't update. But it seems like it behaves in other frameworks like angular's mat-slider same way. I don't know if this is a problem

@henon
Copy link
Collaborator

henon commented May 5, 2024

If it becomes a problem we'll find a solution later. Hasn't been one in 3+ years so don't hold your breath ;)

@danielchalmers
Copy link
Contributor

Thanks @ScarletKuro. I think it's strange that you have to use a different binding when Value works for the other inputs but I'm just looking forward to having the functionality.

I updated to the new property (Point.SleepHours is decimal?)

- <MudSlider @bind-Value="Point.SleepHours" Variant="Variant.Filled" Min="0" Max="24" Step="0.5m" Size="Size.Large" Immediate />
+ <MudSlider @bind-NullableValue="Point.SleepHours" Variant="Variant.Filled" Min="0" Max="24" Step="0.5m" Size="Size.Large" Immediate />

But get build errors:

Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback<decimal?>' to 'Microsoft.AspNetCore.Components.EventCallback'

The type or namespace name 'T' could not be found in the global namespace (are you missing an assembly reference?)

If I add T="decimal?" (which I'm not surprised doesn't work):

The type 'decimal?' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'MudSlider<T>'

@ScarletKuro
Copy link
Member Author

If I add T="decimal?" (which I'm not surprised doesn't work):

Try T=decimal

@ScarletKuro
Copy link
Member Author

ScarletKuro commented May 5, 2024

<MudSlider T="decimal" @bind-NullableValue="_point.SleepHours" Variant="Variant.Filled" Min="0" Max="24" Step="0.5m" Size="Size.Large" Immediate />

@code {
    private readonly Point _point = new();

    public class Point
    {
        public decimal? SleepHours { get; set; }
    }
}

This just works for me. I guess blazor is having hard time to guess the generics in this case. Since some values are int(min, max) some are decimals (step) and the bind value is nullable.
Btw, Immediate is the default behavior in the slider.

If I add T="decimal?" (which I'm not surprised doesn't work):

You are not suppose to set decimal? in the generics as the NullableValue is already a Nullable, it's just decimal.

@ScarletKuro
Copy link
Member Author

I think it's strange that you have to use a different binding when Value works for the other inputs

Well, we discussed multiples times before if having two value bindings is an adequate solution, and we agreed with @henon that it is.
We even planned to use it in datepicker, but then realized there is too much combinations DateTime, DateOnly, DateTimeOffset + nullable variants.

Copy link
Contributor

@danielchalmers danielchalmers left a comment

Choose a reason for hiding this comment

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

+<MudSlider T="decimal" @bind-NullableValue="Point.SleepHours" Variant="Variant.Filled" Min="0" Max="24" Step="0.5m" Size="Size.Large" />

Worked 👍

@ScarletKuro
Copy link
Member Author

Added tests.
Feel free to merge whenever if these changes are ok.

@henon henon merged commit fdb7151 into MudBlazor:dev May 6, 2024
4 checks passed
@henon
Copy link
Collaborator

henon commented May 6, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change API that needs approval breaking change enhancement New feature or request v7 New major MudBlazor version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MudSlider no longer accepts nullable types
3 participants