MudBlazor / MudBlazor

Blazor Component Library based on Material design with an emphasis on ease of use. Mainly written in C# with Javascript kept to a bare minimum it empowers .NET developers to easily debug it if needed.
http://mudblazor.com
MIT License
7.58k stars 1.22k forks source link

Predefine start or end date in MudDateRangePicker #8584

Open Hirad2hhk opened 3 months ago

Hirad2hhk commented 3 months ago

Feature request type

Enhance component

Component name

MudDateRangePicker

Is your feature request related to a problem?

I tried to pre select the start date of the range but through no solution could achieve this and couldn't get any help

Describe the solution you'd like

It would be very handy to be able to pre-select and fix start or end date of the range

Have you seen this feature anywhere else?

No response

Describe alternatives you've considered

No response

Pull Request

Code of Conduct

digitaldirk commented 3 months ago

Hi,

You can set the start, end, or both dates by doing this:

<MudDateRangePicker @bind-DateRange="@dateRange"/>
// Only set start
DateRange dateRange = new DateRange(DateTime.Now.Date, null);
//OR
// Only set end
DateRange dateRange = new DateRange(null, DateTime.Now.Date);
//OR
// Set both
DateRange dateRange = new DateRange(DateTime.Now.Date, DateTime.Now.AddDays(5).Date);

Result (only setting start): image

Is this what you are looking for?

Hirad2hhk commented 2 months ago

Hi @digitaldirk , Thanks for your reply, I Know that it works for the text field, the issue is that the fixation doesn't work for the calendar itself. for example, when the start date is fixed the first click in the calendar is still taking input for the start of the range. also preselecting the dates like you mentioned sometimes cause blank fields and lags. there are some methods mentioned the api by mud like SelectStart and others but they don't work right.