File tree Expand file tree Collapse file tree
src/BootstrapBlazor/Components/DateTimePicker Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -287,6 +287,14 @@ public string? Format
287287 [ Parameter ]
288288 public bool ShowHolidays { get ; set ; }
289289
290+ /// <summary>
291+ /// <para lang="zh">获得/设置 是否选择今天 默认 false</para>
292+ /// <para lang="en">Gets or sets Whether to Select Today. Default is false</para>
293+ /// </summary>
294+ /// <remarks>当 Value 值为 null 且组件设置了 <see cref="DateTimePicker{TValue}.MinValue"/> 的值是,当前选中时间为当天, <see cref="DateTimePicker{TValue}.MinValue"/> 不为空类型时此参数生效</remarks>
295+ [ Parameter ]
296+ public bool SelectToday { get ; set ; }
297+
290298 /// <summary>
291299 /// <para lang="zh">获取/设置 获得自定义禁用日期回调方法,默认 null 内部默认启用数据缓存 可通过 <see cref="EnableDisabledDaysCache"/> 参数关闭</para>
292300 /// <para lang="en">Gets or sets Callback Method to Get Custom Disabled Days. Default is null. Internal Default Enable Data Cache. Can be Closed via <see cref="EnableDisabledDaysCache"/> Parameter</para>
@@ -373,7 +381,7 @@ protected override void OnParametersSet()
373381 }
374382 else
375383 {
376- SelectedValue = Value == null ? ( MinValue ?? DateTime . MinValue ) : ( DateTime ) ( object ) Value ;
384+ SelectedValue = Value == null ? ( ( SelectToday ? DateTime . Today : MinValue ) ?? DateTime . MinValue ) : ( DateTime ) ( object ) Value ;
377385 }
378386
379387 if ( MinValue > SelectedValue )
Original file line number Diff line number Diff line change @@ -296,6 +296,32 @@ public void MinValue_Ok()
296296 Assert . Equal ( DateTime . Today , cut . Instance . Value . Date ) ;
297297 }
298298
299+ [ Fact ]
300+ public void SelectToday_Ok ( )
301+ {
302+ var cut = Context . Render < DateTimePicker < DateTime > > ( builder =>
303+ {
304+ builder . Add ( a => a . SelectToday , true ) ;
305+ } ) ;
306+ Assert . Equal ( DateTime . Today , cut . Instance . Value ) ;
307+
308+ cut . Render < DateTimePicker < DateTime > > ( pb =>
309+ {
310+ pb . Add ( a => a . MinValue , DateTime . Today . AddDays ( - 1 ) ) ;
311+ pb . Add ( a => a . SelectToday , true ) ;
312+ } ) ;
313+ Assert . Equal ( DateTime . Today , cut . Instance . Value ) ;
314+
315+ cut . Render ( pb =>
316+ {
317+ pb . Add ( a => a . Value , DateTime . MinValue ) ;
318+ pb . Add ( a => a . MinValue , DateTime . Today . AddDays ( - 1 ) ) ;
319+ pb . Add ( a => a . SelectToday , false ) ;
320+ } ) ;
321+ Assert . Equal ( DateTime . Today . AddDays ( - 1 ) . Date , cut . Instance . Value . Date ) ;
322+
323+ }
324+
299325 [ Fact ]
300326 public void OnTimeChanged_Ok ( )
301327 {
You can’t perform that action at this time.
0 commit comments