typeahead下拉结果向右对齐-向右拉

typeahead dropdown results align right - pull-right

本文关键字:右对齐 结果 typeahead      更新时间:2023-09-26

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

问题:

  • 输入位于窗口的RHS上(这对于搜索输入框来说是典型的)
  • 我的结果比我的输入(以及包含的div)更宽
  • 我需要下拉列表的右侧与输入框的右侧对齐,并在左侧延伸超过(下面)输入宽度
  • (下拉框只需要移动,其中的文本对齐方式不会改变,应该保持左对齐。即不是本期中的RTL:angularjs bootstrap';s typeahead的RTL)

pull-right类应用于包含div似乎不会影响与输入无关的下拉列表
我不知道还能放在哪里?

是否有CSS方法来控制下拉div的对齐?

修改了以下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>

我研究了以下问题,这些问题似乎对我没有帮助:

  • SO问题22075432-打字对齐问题
  • github引导程序问题2045

您需要重写通过typeahead为.drop-down-menu生成的内联样式。大致如下:

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

Plunker

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


更新

对于非jQuery版本,您必须使用!important 覆盖.dropdown-menuleft css属性

.dropdown-menu{
  left: auto !important;
  right:10px;
}

更新的Plunker

另一个选项是使用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>