up/down arrow key issue with typeahead control (angular bootstrap UI)

前端 未结 4 1003
自闭症患者
自闭症患者 2020-11-30 09:05

Check this PLNKR , i have implemented typeahead control, By default in type ahead control they are not setting any max-height or height to list, but as per

4条回答
  •  隐瞒了意图╮
    2020-11-30 09:51

    The accepted solution will fail if the main window is already scrolling. @user1690588 was on the right track.

    Edit the ui-bootstrap-tpls-0.13.3.js and drop this in around line 5205 above .filter('typeaheadHighlight') at least until the AngularUI team decides to fix this. As well as applying the other change to the template that the accepted solution references.

    .directive('shouldFocus', function () {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                scope.$watch(attrs.shouldFocus, function (newVal, oldVal) {
                    if (newVal && element.prop("class").indexOf("active")) {
                        var par = element.parent("ul");
                        var scrollingTo = element.offset().top - par.offset().top + par.scrollTop();
                        // uncomment below section if you want the selected content to be 
                        // viewed at half the box height
                        // scrollingTo = scrollingTo - (par.height() / 2); 
                        par.scrollTop(scrollingTo);
                    }
                });
            }
        }
    })
    

    Also if you want to get rid of the mouse artifact where it starts scrolling up until it hits the first entry or down till hits the last entry then remove from the template the ng-mouseenter attribute.

提交回复
热议问题