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

Add Focused class/style to BitTimePicker (#8375) #8399

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Bit.BlazorUI;

public partial class BitTimePicker : BitInputBase<TimeSpan?>, IAsyncDisposable
{
private bool _hasFocus;
private bool _disposed;
private string? _labelId;
private string? _inputId;
private string _calloutId = string.Empty;
private string _focusClass = string.Empty;
private string _timePickerId = string.Empty;
private ElementReference _inputHourRef = default!;
private ElementReference _inputMinuteRef = default!;
Expand Down Expand Up @@ -282,12 +282,14 @@ protected override void RegisterCssClasses()

ClassBuilder.Register(() => Standalone ? "bit-tpc-sta" : string.Empty);

ClassBuilder.Register(() => _focusClass);
ClassBuilder.Register(() => _hasFocus ? $"bit-tpc-foc {Classes?.Focused}" : string.Empty);
}

protected override void RegisterCssStyles()
{
StyleBuilder.Register(() => Styles?.Root);

StyleBuilder.Register(() => _hasFocus ? Styles?.Focused : string.Empty);
}

protected override void OnInitialized()
Expand Down Expand Up @@ -351,26 +353,29 @@ private async Task HandleOnFocusIn()
{
if (IsEnabled is false) return;

_focusClass = "bit-tpc-foc";
_hasFocus = true;
ClassBuilder.Reset();
StyleBuilder.Reset();
await OnFocusIn.InvokeAsync();
}

private async Task HandleOnFocusOut()
{
if (IsEnabled is false) return;

_focusClass = string.Empty;
_hasFocus = false;
ClassBuilder.Reset();
StyleBuilder.Reset();
await OnFocusOut.InvokeAsync();
}

private async Task HandleOnFocus()
{
if (IsEnabled is false) return;

_focusClass = "bit-tpc-foc";
_hasFocus = true;
ClassBuilder.Reset();
StyleBuilder.Reset();
await OnFocus.InvokeAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public class BitTimePickerClassStyles
/// </summary>
public string? Root { get; set; }

/// <summary>
/// Custom CSS classes/styles for the focused of the BitTimePicker.
/// </summary>
public string? Focused { get; set; }

/// <summary>
/// Custom CSS classes/styles for the label of the BitTimePicker.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ public partial class BitTimePickerDemo
Description = "Custom CSS classes/styles for the root element of the BitTimePicker."
},
new()
{
Name = "Focused",
Type = "string?",
DefaultValue = "null",
Description = "Custom CSS classes/styles for the focused state of the BitTimePicker."
},
new()
{
Name = "Label",
Type = "string?",
Expand Down
Loading