Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Issue #148 - Add up direction to dropdown rendering. #836

Merged
merged 6 commits into from
May 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/bootstrap.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</script>
<![endif]-->

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular-sanitize.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular-sanitize.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.css">

<!-- ui-select files -->
Expand Down
4 changes: 2 additions & 2 deletions examples/select2-bootstrap3.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</script>
<![endif]-->

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular-sanitize.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.css">

<!--
Expand Down
4 changes: 2 additions & 2 deletions examples/selectize-bootstrap3.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</script>
<![endif]-->

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular-sanitize.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.css">

<!--
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/choices.tpl.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul class="ui-select-choices ui-select-choices-content dropdown-menu"
<ul class="ui-select-choices ui-select-choices-content ui-select-dropdown dropdown-menu"
role="listbox"
ng-show="$select.items.length > 0">
<li class="ui-select-choices-group" id="ui-select-choices-{{ $select.generatedId }}" >
Expand Down
43 changes: 42 additions & 1 deletion src/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ body > .select2-container.open {
z-index: 9999; /* The z-index Select2 applies to the select2-drop */
}

/* Handle up direction Select2 */
.ui-select-container[theme="select2"].direction-up .ui-select-match {
border-radius: 4px; /* FIXME hardcoded value :-/ */
border-top-left-radius: 0;
border-top-right-radius: 0;
}
.ui-select-container[theme="select2"].direction-up .ui-select-dropdown {
border-radius: 4px; /* FIXME hardcoded value :-/ */
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;

border-top-width: 1px; /* FIXME hardcoded value :-/ */
border-top-style: solid;

box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25);

margin-top: -4px; /* FIXME hardcoded value :-/ */
}
.ui-select-container[theme="select2"].direction-up .ui-select-dropdown .select2-search {
margin-top: 4px; /* FIXME hardcoded value :-/ */
}
.ui-select-container[theme="select2"].direction-up.select2-dropdown-open .ui-select-match {
border-bottom-color: #5897fb;
}

/* Selectize theme */

/* Helper class to show styles when focus */
Expand All @@ -62,6 +87,12 @@ body > .select2-container.open {
border-color: #D44950;
}

/* Handle up direction Selectize */
.ui-select-container[theme="selectize"].direction-up .ui-select-dropdown {
box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25);

margin-top: -2px; /* FIXME hardcoded value :-/ */
}

/* Bootstrap theme */

Expand Down Expand Up @@ -99,6 +130,11 @@ body > .select2-container.open {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.input-group > .ui-select-bootstrap > input.ui-select-search.form-control.direction-up {
border-radius: 4px !important; /* FIXME hardcoded value :-/ */
border-top-right-radius: 0 !important;
border-bottom-right-radius: 0 !important;
}

.ui-select-bootstrap > .ui-select-match > .btn{
/* Instead of center because of .btn */
Expand Down Expand Up @@ -210,4 +246,9 @@ body > .ui-select-bootstrap.open {
/* Mark invalid Bootstrap */
.ui-select-bootstrap.ng-dirty.ng-invalid > button.btn.ui-select-match {
border-color: #D44950;
}
}

/* Handle up direction Bootstrap */
.ui-select-container[theme="bootstrap"].direction-up .ui-select-dropdown {
box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.25);
}
4 changes: 2 additions & 2 deletions src/select2/select-multiple.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
ondrop="return false;">
</li>
</ul>
<div class="select2-drop select2-with-searchbox select2-drop-active"
<div class="ui-select-dropdown select2-drop select2-with-searchbox select2-drop-active"
ng-class="{'select2-display-none': !$select.open}">
<div class="ui-select-choices"></div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion src/select2/select.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'select2-container-active': $select.focus,
'select2-allowclear': $select.allowClear && !$select.isEmpty()}">
<div class="ui-select-match"></div>
<div class="select2-drop select2-with-searchbox select2-drop-active"
<div class="ui-select-dropdown select2-drop select2-with-searchbox select2-drop-active"
ng-class="{'select2-display-none': !$select.open}">
<div class="select2-search" ng-show="$select.searchEnabled">
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
Expand Down
2 changes: 1 addition & 1 deletion src/selectize/choices.tpl.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-show="$select.open" class="ui-select-choices selectize-dropdown single">
<div ng-show="$select.open" class="ui-select-choices ui-select-dropdown selectize-dropdown single">
<div class="ui-select-choices-content selectize-dropdown-content">
<div class="ui-select-choices-group optgroup" role="listbox">
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label optgroup-header" ng-bind="$group.name"></div>
Expand Down
42 changes: 42 additions & 0 deletions src/uiSelectDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,48 @@ uis.directive('uiSelect',
element[0].style.top = '';
element[0].style.width = originalWidth;
}

// Hold on to a reference to the .ui-select-dropdown element for direction support.
var dropdown = null,
directionUpClassName = 'direction-up';

// Support changing the direction of the dropdown if there isn't enough space to render it.
scope.$watch('$select.open', function(isOpen) {
if (isOpen) {
dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown');
if (dropdown === null) {
return;
}

// Hide the dropdown so there is no flicker until $timeout is done executing.
dropdown[0].style.visibility = 'hidden';

// Delay positioning the dropdown until all choices have been added so its height is correct.
$timeout(function(){
var offset = uisOffset(element);
var offsetDropdown = uisOffset(dropdown);

// Determine if the direction of the dropdown needs to be changed.
if (offset.top + offset.height + offsetDropdown.height > $document[0].documentElement.scrollTop + $document[0].documentElement.clientHeight) {
dropdown[0].style.position = 'absolute';
dropdown[0].style.top = (offsetDropdown.height * -1) + 'px';
element.addClass(directionUpClassName);
}

// Display the dropdown once it has been positioned.
dropdown[0].style.visibility = '';
});
} else {
if (dropdown === null) {
return;
}

// Reset the position of the dropdown.
dropdown[0].style.position = '';
dropdown[0].style.top = '';
element.removeClass(directionUpClassName);
}
});
};
}
};
Expand Down