Background : Utilizing Bootstrap 4, I have numerous buttons incorporating SVG + span for the button text, as illustrated below :
<button class="btn--color-success">
<span>Button label</span>
<svg><svg>
</button>
The objective is to hide the span when clicking on the button and replace the SVG with a loading icon, essentially transforming it into a "loading" button. While changing the SVG is not an issue, the main concern lies in smoothly transitioning the span and maintaining the button width.
I've managed to achieve this by setting a max-width for the button's span, but encounter difficulties when dealing with two buttons within a standard BS4 row/col configuration with justify-content-end alignment, making the shrink effect somewhat abrupt. I'm striving to enhance the transition for a smoother output.
Here's a fiddle showcasing the problem within a 400px wide container:
body {
max-width: 400px;
}
.row [class*='col-'] {
transition: all .3s;
}
button {
display: inline-flex;
align-items: center;
justify-content : center;
overflow: hidden;
max-width: 100%;
transition: all .3s;
}
button span {
overflow: hidden;
white-space: nowrap;
max-width: 100%;
transition: max-width .3s;
}
button.btn--shrink span {
max-width: 0;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/css/bootstrap.min.css" integrity="sha384-PDle/QlgIONtM1aqA2Qemk5gPOE7wFq8+Em+G/hmo5Iq0CCmYZLv3fVRDJ4MMwEA" crossorigin="anonymous">
<title>Hello, world!</title;
</head>
<body>
<div class="row justify-content-end">
<div class="col-auto">
<button>
<span>A button</span>
</button>
</div>
<div class="col-auto">
<button onclick="this.classList.toggle('btn--shrink')">
<span>A shrinkable button</span>
</button>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/js/bootstrap.min.js" integrity="sha384-7aThvCh9TypR7fIc2HV4O/nFMVCBwyIUKL8XCtKE+8xgCgl/PQGuFsvShjr74PBp" crossorigin="anonymous"></script>
</body>
</html>
I've explored various solutions on Stack Overflow without success in resolving my specific issue. Though seemingly straightforward, I remain stuck and seek assistance in tackling this matter.
Your help is greatly appreciated.