typeahead下拉结果右 - 右 - 右

时间:2015-03-31 07:01:14

标签: javascript angularjs twitter-bootstrap typeahead angularjs-bootstrap

尝试了解如何仅在angular typeahead下拉列表中实现pull-right类。

问题:

  • 输入位于窗口的RHS(搜索输入框的典型值)
  • 我的结果比我的输入(和包含div)
  • 更宽
  • 我需要下拉列表的右侧与输入框的右侧对齐,并在输入宽度的左侧(下方)延伸。
  • (下拉列表只需要移位,内部的文本对齐不会改变,并且应保持与左对齐。即,不是本期问题中的RTL:RTL for angularjs bootstrap's typeahead

pull-right类应用于包含div似乎不会独立于输入而影响下拉列表 我不知道还能把它放在哪里呢?

是否有一种控制下拉列表对齐的CSS方法?

修改了以下documentation example中的Plunker

  • 包含包含div
  • 中的pull-right
  • 放在一个包含div中以缩小宽度(可能不必要?)

如果您在plunker示例输入框中键入“ ang ”,您会看到结果溢出窗口右侧。

  <div class='column'>
    <div class='container-fluid pull-right' ng-controller="TypeaheadCtrl">
      <h4>Asynchronous results</h4>
      <pre>Model: {{asyncSelected | json}}</pre>
      <input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" typeahead="address for address in getLocation($viewValue)" typeahead-loading="loadingLocations" class="form-control">
      <i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
    </div>
  </div>

我看过以下问题,似乎对我没有帮助:

2 个答案:

答案 0 :(得分:3)

您需要覆盖由typeahead为.drop-down-menu生成的内联样式。类似的东西:

<script>
  $('#myInput').on('keypup', function() {
    $(".dropdown-menu").css({ "left": "auto", "right": "10px" });
  });
</script>

Plunker

注意:将right设置为input与页面/窗口的RHS之间的距离

<小时/> 的更新

对于非jQuery版本,您必须使用left

覆盖.dropdown-menu的{​​{1}} css属性
!important

<强> Updated Plunker

答案 1 :(得分:0)

另一种选择是使用typeahead-popup-template-url挂钩,对默认模板实现稍作修改。

使用这种方法,您可以使用多个ui-typeahead实例逐个定义所需的布局。

不要忘记根据具体用途调整right长度。

(function () {
	'use strict';

  angular.module('myAnswer', ['ui.bootstrap']);
  
})();
<html ng-app="myAnswer">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
  <div class='container-fluid'>

    <h4>Static arrays</h4>
    <pre>Model: {{selected | json}}</pre>
    
<script type="text/ng-template" id="typeahead-popup-right.html">
  <ul class="dropdown-menu" ng-show="isOpen() && !moveInProgress" ng-style="{top: position().top+'px',left: 'auto', right: '15px'}" role="listbox" aria-hidden="{{!isOpen()}}">
    <li class="uib-typeahead-match" ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index, $event)" role="option" id="{{::match.id}}">
      <div uib-typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
    </li>
  </ul>
</script>    
    
    
    <input type="text" ng-model="selected" uib-typeahead="state for state in ['Espirito Santo', 'Minhas Gerais', 'Rio de Janeiro', 'São Paulo'] | filter:$viewValue" class="form-control" typeahead-popup-template-url="typeahead-popup-right.html">
    <small class="help-block">Try typing 'Rio' or 'Janeiro'</small>
  </div>
  </body>
</html>