Spinner Save Button
Show a spinner in place of a button icon while its action runs. aria-hidden="true" on the spinner keeps the button label as its name. aria-disabled="true" on the button swaps the icon for the spinner and keeps the focus while the script ignores more clicks.
Code
The following example assumes that you have imported the component and set up the theme.
<div class="save-example">10 collapsed lines
<button type="button" class="btn btn-primary save-button"> <!-- Save --> <svg aria-hidden="true" fill="currentColor" viewBox="0 0 24 24"> <path d="M17 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V7l-4-4Zm-5 16a3 3 0 1 1 0-6 3 3 0 0 1 0 6Zm3-10H5V5h10v4Z" /> </svg> <sv-spinner aria-hidden="true"></sv-spinner> Save </button></div>
<script type="application/x-typescript" module>9 collapsed lines
const saveButton = document.querySelector<HTMLButtonElement>(".save-button")!;
saveButton.addEventListener("click", async () => { if (saveButton.ariaDisabled) return;
saveButton.ariaDisabled = "true"; await new Promise(resolve => setTimeout(resolve, 1500)); saveButton.ariaDisabled = null; });</script>
<style>24 collapsed lines
.save-example { display: grid; place-items: center; }
.save-button { display: inline-flex; gap: 0.5em; align-items: center; padding-inline: 0.9em 1.2em;
svg { inline-size: 1em; }
&[aria-disabled] { cursor: progress; }
&[aria-disabled] svg, &:not([aria-disabled]) sv-spinner { display: none; } }</style>