Hi, I am using metronic theme with blazor webapp dotnet 9. I have this code:
@foreach (var parking in Parkings ??= [])
{
<button type="button"
class="btn btn-lg btn-light-primary @(parking.IsActive ? "active" : "") w-100 mb-3"
@onclick="() => { parking.IsActive = !parking.IsActive; }">
@parking.Name
</button>
}addClass and removeClassconst button = bootstrap.Button.getOrCreateInstance(buttonElement)
button.toggle()data-bs-toggle of bootstrapStateHasChanged();btn-light-primary class and as you know, It is by default, a light blue button but after the active class added to element, It is like a button with class btn-primary and it stays in that color or style format until I click on screen so It knows to render the button and show the correct styleHi,
Thank you for reaching out to us.
This is an expected behavior, clicking button activates button active state and active state is selected in styles to override button default color.
.primary:active:not(.btn-active) {
color: var(--bs-primary-inverse);
border-color: var(--bs-primary-active);
background-color: var(--bs-primary-active)
}btn-active class.thank you,
as you said, I changed my code to manually add and remove btn-active class but now it doesn't even activate the active style!
current code:
<button type="button"
class="btn btn-lg btn-light-primary @(parking.IsActive ? "btn-active" : "") w-100 mb-3"
@onclick="() => ToggleParking(parking)">
@parking.Name
</button>btn-active class):active class:Hi Ali,
Other solution you can try is manually remove the active state in your button click handler.
JS.InvokeVoidAsync("eval", "document.activeElement?.blur()");