-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
DatePicker and DateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates #1862
Conversation
@@ -35,6 +35,12 @@ protected async Task SetDateAsync(DateTime? date, bool updateValue) | |||
{ | |||
if (_value != date) | |||
{ | |||
if (date is not null && IsDateDisabled(date.Value.Date)) |
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.
don't we risk a nullref exception if the func is set to null? I would suggest, make the default value of the func parameter null in the first place (meaning nothing is disabled) and call it only when it is not null.
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.
Good point - I added some logic to the prop to ensure the prop is always non-null and returns the "default"/safe value. I prefer this opposed to a nullable prop, but me me know if you really prefer a nullable prop and I'll be happy to change it.
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.
On the latest dev branch this will throw a null reference exception when either Start
or End
are null.
I ran into this while trying to create unit test for PR #1887
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.
Who wants to PR a fix + test?
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.
@henon, can you assign this to me.
I love that you added a bunch of tests! |
This PR is ok by me. @tungi52, regarding the range picker you are the expert. can we merge? |
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.
@henon Yes, from my side it is ok. @mtrdp642 nice work!
} | ||
set | ||
{ | ||
if (value is null) |
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.
Personally I like a bit of space in my code, but surely the setter code can be condensed to a oneliner?
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.
I would agree and I would not write it like that myself. But I don't care enough ...
For me priorities are stability, maintainability, functional correctness and then some and personal coding preferneces are almost last.
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.
I can be a bit of code purist. Code should always be beautiful :)
But stability and maintainability should go first, agree yeah.
* Refined Drawer documentation. * Added MudVirtualize, a Virtualize which can be switched off * Fixed MudVirtualize API test (cherry picked from commit c8bd5d1) * Added Table Virtualization. (#796, #1847) * Added Table Virtualization. * Fix formatting... * Missing @using for virtualize * Use MudVirtualize instead of Virtualize * Fixed MudVirtualize API test * Removed unused usings Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com> * Autocomplete: Added Required parameter (#1499, #1829) * Added "Required" argument to Autocomplete * Added MudAutocomplete and MudSelect unit tests for the Required attribute. * Refined unit tests * Added "Required" argument to Autocomplete * Added MudAutocomplete and MudSelect unit tests for the Required attribute. * Refined unit tests Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com> * MudSelect and MudAutocomplete: Adornment improvements (#804, #912, #1659, #1835) * Select and Autocomplete improvements * -Select Adornment.End now variable; -Select/Autocomplete enabled AdornmentIcon; * merge * -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values; - * Switched MudSelect and MudAutocomplete CurrentIcon condition * -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete; -Docs refinment: Set ShowCode="false" for Variants example; * -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon; -Removed test app; * MudSelect: Added @attributes="UserAttributes" to satisfy unit test. * Made CurrentIcon private and renamed to _currentIcon * Removed test app * -Changed method MudAutocomplete.UpdateIcon() to private; -Changed method MudSelect.UpdateIcon() to private; -Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon; * Select and Autocomplete improvements * -Select Adornment.End now variable; -Select/Autocomplete enabled AdornmentIcon; * merge * -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values; - * Switched MudSelect and MudAutocomplete CurrentIcon condition * -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete; -Docs refinment: Set ShowCode="false" for Variants example; * -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon; -Removed test app; * MudSelect: Added @attributes="UserAttributes" to satisfy unit test. * Made CurrentIcon private and renamed to _currentIcon * Removed test app * -Changed method MudAutocomplete.UpdateIcon() to private; -Changed method MudSelect.UpdateIcon() to private; -Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon; Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com> * TabPanel: Allow HTML markup in Text (#1907, #1917) * Add MarkupString for Tab text * Added test case for html text tabs Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr> * Docs: improved autocomplete validation example * MudForm: improved the IsValid tow-way binding fix (previous fix was buggy) * DatePicker and DateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates (#1862) * (feat): add IsDateDisabled functionality * changed prop name to follow convention * ensure prop can never be null * fix default prop value Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com> Co-authored-by: JJ Banda <=> * Refined Drawer documentation. Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com> Co-authored-by: Terry Phillips <terry.w.phillips@gmail.com> Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com> Co-authored-by: aastovas <79198906+aastovas@users.noreply.github.com> Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr> Co-authored-by: JJ Banda <mtrdp642@gmail.com>
* Fixes #1577 * Update README.md * Fixes #1577 * Flips switch in RTL * Added MudVirtualize, a Virtualize which can be switched off * Fixed MudVirtualize API test (cherry picked from commit c8bd5d1) * Added Table Virtualization. (#796, #1847) * Added Table Virtualization. * Fix formatting... * Missing @using for virtualize * Use MudVirtualize instead of Virtualize * Fixed MudVirtualize API test * Removed unused usings Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com> * Autocomplete: Added Required parameter (#1499, #1829) * Added "Required" argument to Autocomplete * Added MudAutocomplete and MudSelect unit tests for the Required attribute. * Refined unit tests * Added "Required" argument to Autocomplete * Added MudAutocomplete and MudSelect unit tests for the Required attribute. * Refined unit tests Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com> * MudSelect and MudAutocomplete: Adornment improvements (#804, #912, #1659, #1835) * Select and Autocomplete improvements * -Select Adornment.End now variable; -Select/Autocomplete enabled AdornmentIcon; * merge * -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values; - * Switched MudSelect and MudAutocomplete CurrentIcon condition * -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete; -Docs refinment: Set ShowCode="false" for Variants example; * -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon; -Removed test app; * MudSelect: Added @attributes="UserAttributes" to satisfy unit test. * Made CurrentIcon private and renamed to _currentIcon * Removed test app * -Changed method MudAutocomplete.UpdateIcon() to private; -Changed method MudSelect.UpdateIcon() to private; -Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon; * Select and Autocomplete improvements * -Select Adornment.End now variable; -Select/Autocomplete enabled AdornmentIcon; * merge * -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values; - * Switched MudSelect and MudAutocomplete CurrentIcon condition * -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete; -Docs refinment: Set ShowCode="false" for Variants example; * -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon; -Removed test app; * MudSelect: Added @attributes="UserAttributes" to satisfy unit test. * Made CurrentIcon private and renamed to _currentIcon * Removed test app * -Changed method MudAutocomplete.UpdateIcon() to private; -Changed method MudSelect.UpdateIcon() to private; -Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon; Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com> * TabPanel: Allow HTML markup in Text (#1907, #1917) * Add MarkupString for Tab text * Added test case for html text tabs Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr> * Docs: improved autocomplete validation example * MudForm: improved the IsValid tow-way binding fix (previous fix was buggy) * DatePicker and DateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates (#1862) * (feat): add IsDateDisabled functionality * changed prop name to follow convention * ensure prop can never be null * fix default prop value Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com> Co-authored-by: JJ Banda <=> * Fixes #1577 * Refined Drawer documentation. (#1909) * Refined Drawer documentation. * Added MudVirtualize, a Virtualize which can be switched off * Fixed MudVirtualize API test (cherry picked from commit c8bd5d1) * Added Table Virtualization. (#796, #1847) * Added Table Virtualization. * Fix formatting... * Missing @using for virtualize * Use MudVirtualize instead of Virtualize * Fixed MudVirtualize API test * Removed unused usings Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com> * Autocomplete: Added Required parameter (#1499, #1829) * Added "Required" argument to Autocomplete * Added MudAutocomplete and MudSelect unit tests for the Required attribute. * Refined unit tests * Added "Required" argument to Autocomplete * Added MudAutocomplete and MudSelect unit tests for the Required attribute. * Refined unit tests Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com> * MudSelect and MudAutocomplete: Adornment improvements (#804, #912, #1659, #1835) * Select and Autocomplete improvements * -Select Adornment.End now variable; -Select/Autocomplete enabled AdornmentIcon; * merge * -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values; - * Switched MudSelect and MudAutocomplete CurrentIcon condition * -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete; -Docs refinment: Set ShowCode="false" for Variants example; * -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon; -Removed test app; * MudSelect: Added @attributes="UserAttributes" to satisfy unit test. * Made CurrentIcon private and renamed to _currentIcon * Removed test app * -Changed method MudAutocomplete.UpdateIcon() to private; -Changed method MudSelect.UpdateIcon() to private; -Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon; * Select and Autocomplete improvements * -Select Adornment.End now variable; -Select/Autocomplete enabled AdornmentIcon; * merge * -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values; - * Switched MudSelect and MudAutocomplete CurrentIcon condition * -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete; -Docs refinment: Set ShowCode="false" for Variants example; * -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon; -Removed test app; * MudSelect: Added @attributes="UserAttributes" to satisfy unit test. * Made CurrentIcon private and renamed to _currentIcon * Removed test app * -Changed method MudAutocomplete.UpdateIcon() to private; -Changed method MudSelect.UpdateIcon() to private; -Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon; Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com> * TabPanel: Allow HTML markup in Text (#1907, #1917) * Add MarkupString for Tab text * Added test case for html text tabs Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr> * Docs: improved autocomplete validation example * MudForm: improved the IsValid tow-way binding fix (previous fix was buggy) * DatePicker and DateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates (#1862) * (feat): add IsDateDisabled functionality * changed prop name to follow convention * ensure prop can never be null * fix default prop value Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com> Co-authored-by: JJ Banda <=> * Refined Drawer documentation. Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com> Co-authored-by: Terry Phillips <terry.w.phillips@gmail.com> Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com> Co-authored-by: aastovas <79198906+aastovas@users.noreply.github.com> Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr> Co-authored-by: JJ Banda <mtrdp642@gmail.com> * Fixes #1577 * Fixes #1577 Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com> Co-authored-by: Jonas B <jonasmitb@gmail.com> Co-authored-by: Terry Phillips <terry.w.phillips@gmail.com> Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com> Co-authored-by: aastovas <79198906+aastovas@users.noreply.github.com> Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr> Co-authored-by: JJ Banda <mtrdp642@gmail.com>
I have a use case for the
MudDatePicker
where I would like to prevent users from selecting certain dates within the picker's calendar. Currently the only functionality to support anything like this are theMinDate
andMaxDate
component parameters, but these don't prevent the user from selecting any arbitrary dates/ranges (for example: prevent the user from selecting dates after the 5th of each month; or given a set of dates, only allow for date selection within this set).Add the ability for users to set a
Func<DateTime, bool> IsDateDisabled
component parameter: if this returns true for a given calendar date, the calendar date button is disabled, preventing the user's selection. This also works for theMudDateRangePicker
by only allowing for ranges to be picked if no date between the range's start and end dates return true for the provided function.I was going to handle form validation for this feature as well, but I noticed there wasn't any validation logic for the
MinDate
andMaxDate
either, so I wasn't sure of the best way to handle this.