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,40 @@ 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 . Value , null ) ;
305+ builder . Add ( a => a . SelectToday , true ) ;
306+ } ) ;
307+ Assert . Null ( cut . Instance . Value ) ;
308+
309+ // 点击确定
310+ var buttons = cut . FindAll ( ".picker-panel-footer button" ) ;
311+ cut . InvokeAsync ( ( ) => buttons [ 1 ] . Click ( ) ) ;
312+
313+ Assert . Equal ( DateTime . Today , cut . Instance . Value ) ;
314+
315+
316+ cut . Render ( pb =>
317+ {
318+ pb . Add ( a => a . MinValue , DateTime . Today . AddDays ( - 1 ) ) ;
319+ pb . Add ( a => a . SelectToday , true ) ;
320+ } ) ;
321+ Assert . Equal ( DateTime . Today , cut . Instance . Value ) ;
322+
323+ cut . Render ( pb =>
324+ {
325+ pb . Add ( a => a . Value , DateTime . MinValue ) ;
326+ pb . Add ( a => a . MinValue , DateTime . Today . AddDays ( - 1 ) ) ;
327+ pb . Add ( a => a . SelectToday , false ) ;
328+ } ) ;
329+ Assert . Equal ( DateTime . Today . AddDays ( - 1 ) . Date , cut . Instance . Value ? . Date ) ;
330+
331+ }
332+
299333 [ Fact ]
300334 public void OnTimeChanged_Ok ( )
301335 {
You can’t perform that action at this time.
0 commit comments