New Metronic Docs!Added Integration Docs with Starter Kits Apps for Laravel, Laravel Livewire, Angular, Vue, Symfony, Blazor Server, Django & Flask & more
Browse Docs

Deactivate an Activated Button


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>
}

the problem is that when I click on the button, It gets active class and when I click again, the active class will remove. but after the removal of active class, the button style remains active (Full Primary Blue) until i click anywhere else on the screen.

I tried
1- jquery addClass and removeClass
2- bootstrap :

const button = bootstrap.Button.getOrCreateInstance(buttonElement)
button.toggle()

3- use data-bs-toggle of bootstrap
4- calling StateHasChanged();

none of them worked. button stays in active style until click somewhere else. I mean for example this button has 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 style


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)

Deleted comment

Hi,

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)
}

If you want manually handle button active state you can use btn-active class.

Regards,
Lauris Stepanovs,
Keenthemes Support Team



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>

here is the video to see new code effect (btn-active class):

video


and here is the effect of active class:

video2


Deleted comment
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(