0

Plunkr is here

Definitely not a CSS transition/guru, but I'm trying to make clicking on an icon slide in the input. I have this working, but as soon as the animation is finished my icon blows up to the width of the containing div and I'm not sure why.

Markup

  <form class="form">
    <div class="input-group col-sm-5">
      <span class="btn btn-default input-group-addon" ng-click="hideInput = !hideInput">
          <span class="glyphicon glyphicon-flag"></span>
      </span>
      <input class="form-control animate-hide" ng-hide="hideInput" />
    </div>
  </form>

Styles

.animate-hide {
  -webkit-transition: all linear 0.75s;
  -o-transition: all linear 0.75s;
  transition: all linear 0.75s;
}
.animate-hide.ng-hide {
  width: 0;
}
.glyphicon-flag {
  color: #d9534f !important;
}

Everything besides the button expanding when the animation complets works great.

1 Answer 1

2

The problem is that the CSS display property of the input-group-addon is set to table-cell by Bootstrap. When your animation is finished, the input is hidden which makes the flag icon expand to take all remaining space. You can fix this in various ways, one simple option is to add an empty span after the input. For example:

<form class="form">
  <div class="input-group col-sm-5">
    <span class="btn btn-default input-group-addon" ng-click="hideInput = !hideInput">
      <span class="glyphicon glyphicon-flag"></span>
    </span>
    <input class="form-control animate-hide" ng-hide="hideInput" />
    <span></span>
  </div>
</form>

Example plunker here: http://plnkr.co/edit/qPvbXtEUzvWfsZPkmVRq?p=preview

Sign up to request clarification or add additional context in comments.

3 Comments

You beat me to it :) One thing that I would change though is instead of using a <span> is to use a <div> instead. This way you have a block level element that you can set the height property on to match the height of the Bootstrap input. Here is my implementation: plnkr.co/edit/qzLJExPQ2EQ3sYqs7wdR?p=preview
@JoshTaylor That's a good call, I just threw any old element in the to demonstrate the issue & solution.
@DavidG @JoshTaylor Great recommendations both of you, I appreciate it. I incorporated both techniques and added padding:6px 0; to prevent the input from "snapping" shut at the end of the animation. Final Plunkr: plnkr.co/edit/XbNc3eNLHm7p0RJtzJu9?p=preview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.