Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular uib-popover displays in wrong position when set on overflowed text

I have a working example of my issue here: http://plnkr.co/edit/vwZS5e?p=preview

Here's the problem span:

<div class="test-container">
    <span uib-popover="Test"
          popover-placement="top"
          popover-trigger="mouseenter"
          popover-append-to-body="true">
        MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe
    </span>
</div>

I'm trying to display a popover above the center of this span when I mouseover it. I'm using text-overflow to cut off my text when it's too long. But it seems like uib-popover doesn't account for the overflow.. the popover appears way too far to the right.

Here's my css:

.test-container {
    text-overflow:ellipsis; 
    overflow:hidden; 
    width:100px; 
    border:1px solid red; 
    margin-top:50px; 
    margin-left:50px;
}

I know I can place the popover on the test-container div, but I'd prefer the popover be in the center of the span.

Does anyone have an idea on how to fix this?

like image 502
nardnob Avatar asked Oct 19 '22 20:10

nardnob


1 Answers

<span> is an inline element and width of an inline element depends on its content. If you will add more content, its width will increase and vice versa.

In above situation, you have very long string of text even without spaces. If you will inspect your <span> you will see that the width of <span> is much larger than the width of its parent .test-container.

uib-popover is taking its position according to the width of <span>. If you will increase or decrease content of <span> element you will see change in position of uib-popover as well.

You can fix this by making <span> a block element and moving text clipping properties on it.

(function(){
  'use strict';

  angular
    .module('app', ['ui.bootstrap', 'ngAnimate']);
})();

(function(){
  'use strict';

  angular
    .module('app')
    .controller('appController', AppController);

  AppController.$inject = ['$log', '$timeout'];

  function AppController($log, $timeout) {
    var vm = this;

    return vm;
  }
})();
html,
body {
  background-color:darkgray;
}

.test-container {
  width:100px; 
  border:1px solid red; 
  margin-top:50px; 
  margin-left:50px;
}

.test-container span {
  text-overflow:ellipsis; 
  overflow:hidden;
  display: block;
}
<link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
  <script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
  <script data-require="bootstrap@*" data-semver="3.3.5" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script data-require="[email protected]" data-semver="1.4.6" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
  <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.14.3/ui-bootstrap-tpls.min.js"></script>

<div ng-app="app" data-ng-controller="appController as vm">
  <div class="test-container">
    <span uib-popover="Test"
          popover-placement="top"
          popover-trigger="mouseenter"
          popover-append-to-body="true">
      MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe
    </span>
  </div>
</div>
like image 136
Mohammad Usman Avatar answered Oct 21 '22 15:10

Mohammad Usman