Skip to content

Commit

Permalink
added a scrolling mechanism to the select dropdown (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
danrot authored and wachterjohannes committed May 10, 2016
1 parent 0aaed55 commit 833b883
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 49 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG for husky

* dev-master
* HOTFIX #646 Added a scrolling mechanism to the select dropdown

* 0.19.1 (2016-04-26)
* HOTFIX #640 Load correct globalize.culture file
* HOTFIX #635 Fixed communication with front dropdown in url-input
Expand Down
11 changes: 9 additions & 2 deletions demos/select/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,20 @@ <h1>Husky Select Demo</h1>
multipleSelect: true,
defaultLabel: 'Please choose ...',
valueName: 'name',
dropdownPadding: 50,
data: [
{id: 0, name: 'Deutsch'},
{id: 1, name: 'English'},
{id: 2, name: 'Spanish'},
{id: 3, name: 'Italienisch'},
{id: 4, name: 'Italienisch mit sehr sehr sehr sehr sehr langem Titel und viel Bla bla'}

{id: 4, name: 'Italienisch mit sehr sehr sehr sehr sehr langem Titel und viel Bla bla'},
{id: 5, name: 'Französisch'},
{id: 6, name: 'Russisch'},
{id: 7, name: 'Finnisch'},
{id: 8, name: 'Schwedisch'},
{id: 9, name: 'Norwegisch'},
{id: 10, name: 'Dänisch'},
{id: 11, name: 'Niederländisch'},
],
preSelectedElements: [1, 2, 3, 4]
}
Expand Down
45 changes: 23 additions & 22 deletions dist/husky.css
Original file line number Diff line number Diff line change
Expand Up @@ -10159,118 +10159,119 @@ a.btn-black, a.btn-highlight {
min-width: 100%;
position: absolute;
top: 20px;
left: 0px;
left: 0;
margin-top: 5px;
background-color: #FFF;
border: 1px solid #ccc;
z-index: 2000;
border-radius: 3px;
overflow: auto;
}
/* line 69, ../scss/modules/select.scss */
/* line 70, ../scss/modules/select.scss */
.husky-select-container .dropdown-list .divider {
max-width: 100%;
height: 1px;
background-color: #ccc;
margin: 5px 0 10px;
}
/* line 76, ../scss/modules/select.scss */
/* line 77, ../scss/modules/select.scss */
.husky-select-container .dropdown-list.top {
top: inherit;
bottom: 5px;
}
/* line 81, ../scss/modules/select.scss */
/* line 82, ../scss/modules/select.scss */
.husky-select-container .dropdown-list .disabled,
.husky-select-container .dropdown-list .disabled:hover {
background: none;
cursor: default;
}
/* line 85, ../scss/modules/select.scss */
/* line 86, ../scss/modules/select.scss */
.husky-select-container .dropdown-list .disabled .item-value,
.husky-select-container .dropdown-list .disabled:hover .item-value {
color: #999;
}
/* line 89, ../scss/modules/select.scss */
/* line 90, ../scss/modules/select.scss */
.husky-select-container .dropdown-list .check {
display: inline;
width: 20px;
margin-right: 10px;
padding-top: 7px;
}
/* line 95, ../scss/modules/select.scss */
/* line 96, ../scss/modules/select.scss */
.husky-select-container .dropdown-list .item-value {
display: inline;
line-height: 30px;
}
/* line 100, ../scss/modules/select.scss */
/* line 101, ../scss/modules/select.scss */
.husky-select-container .dropdown-list > ul {
list-style: none;
margin: 0;
padding: 10px 0;
}
/* line 105, ../scss/modules/select.scss */
/* line 106, ../scss/modules/select.scss */
.husky-select-container .dropdown-list > ul input {
margin: 0;
}
/* line 109, ../scss/modules/select.scss */
/* line 110, ../scss/modules/select.scss */
.husky-select-container .dropdown-list > ul > li {
padding: 0px 20px 0px 20px;
clear: both;
height: 30px;
}
/* line 114, ../scss/modules/select.scss */
/* line 115, ../scss/modules/select.scss */
.husky-select-container .dropdown-list > ul > li > div {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
/* line 120, ../scss/modules/select.scss */
/* line 121, ../scss/modules/select.scss */
.husky-select-container .dropdown-list > ul > li:hover, .husky-select-container .dropdown-list > ul > li.hover {
background-color: #52B6CA;
cursor: pointer;
}
/* line 125, ../scss/modules/select.scss */
/* line 126, ../scss/modules/select.scss */
.husky-select-container .dropdown-list > ul > li:hover .item-value {
color: #fff;
}
/* line 129, ../scss/modules/select.scss */
/* line 130, ../scss/modules/select.scss */
.husky-select-container .dropdown-list > ul > li:hover > div {
color: #fff;
}
/* line 137, ../scss/modules/select.scss */
/* line 138, ../scss/modules/select.scss */
.husky-select-container.small .dropdown-label {
font-size: 10px;
line-height: 20px;
}
/* line 141, ../scss/modules/select.scss */
/* line 142, ../scss/modules/select.scss */
.husky-select-container.small .toggle-icon {
line-height: 20px;
}
/* line 144, ../scss/modules/select.scss */
/* line 145, ../scss/modules/select.scss */
.husky-select-container.small .dropdown-list {
top: 12px;
min-width: 200px;
max-width: 100%;
border-radius: 2px;
}
/* line 150, ../scss/modules/select.scss */
/* line 151, ../scss/modules/select.scss */
.husky-select-container.small .dropdown-list.top {
top: auto;
bottom: -3px;
}
/* line 156, ../scss/modules/select.scss */
/* line 157, ../scss/modules/select.scss */
.husky-select-container.small .husky-select-label {
min-height: 20px;
}
/* line 162, ../scss/modules/select.scss */
/* line 163, ../scss/modules/select.scss */
.husky-select-container.white .dropdown-label {
background: #fff;
}
/* line 168, ../scss/modules/select.scss */
/* line 169, ../scss/modules/select.scss */
.husky-select-container.action .dropdown-label {
background: #52B6CA;
color: #fff;
}
/* line 174, ../scss/modules/select.scss */
/* line 175, ../scss/modules/select.scss */
.husky-select-container select {
opacity: 0;
position: absolute;
Expand Down
29 changes: 18 additions & 11 deletions dist/husky.js
Original file line number Diff line number Diff line change
Expand Up @@ -39578,6 +39578,7 @@ define('__component__$dependent-select@husky',[],function() {
* @param {Boolean} [options.isNative] should use native select
* @param {Boolean} [options.showToolTip] Show tool-tip on hover - only works for single-selects
* @param {Array} [options.defaultValue] Array of default items that should be selected if no item has been preselected
* @param {Number} [options.dropdownPadding] The amount of padding on top or bottom of the dropdown list
*/

define('__component__$select@husky',[], function() {
Expand Down Expand Up @@ -39615,7 +39616,8 @@ define('__component__$select@husky',[], function() {
showToolTip: false,
translations: translations,
isNative: false,
defaultValue: null
defaultValue: null,
dropdownPadding: 0,
},

constants = {
Expand Down Expand Up @@ -40726,24 +40728,30 @@ define('__component__$select@husky',[], function() {
return;
}

this.sandbox.logger.log('show dropdown ' + this.options.instanceName);
this.sandbox.dom.removeClass(this.$dropdownContainer, 'hidden');
this.sandbox.dom.on(this.sandbox.dom.window, 'click.dropdown.' + this.options.instanceName, this.hideDropDown.bind(this));
this.dropdownVisible = true;

this.sandbox.dom.removeClass(this.$dropdownContainer, constants.dropdownTopClass);
var ddHeight = this.sandbox.dom.height(this.$dropdownContainer),
ddTop = this.sandbox.dom.offset(this.$dropdownContainer).top,
var dropdownHeight = this.sandbox.dom.height(this.$dropdownContainer),
dropdownTop = this.sandbox.dom.offset(this.$dropdownContainer).top,
windowHeight = this.sandbox.dom.height(this.sandbox.dom.window),
scrollTop = this.sandbox.dom.scrollTop(this.sandbox.dom.window);
scrollTop = this.sandbox.dom.scrollTop(this.sandbox.dom.window),
dropdownMaxHeight = windowHeight - dropdownTop;

if (this.options.direction === 'top') {
this.sandbox.dom.addClass(this.$dropdownContainer, constants.dropdownTopClass);
} else if (this.options.direction !== 'bottom') {
// check if dropdown container overlaps bottom of browser
if (ddHeight + ddTop > windowHeight + scrollTop) {
this.sandbox.dom.addClass(this.$dropdownContainer, constants.dropdownTopClass);
}
} else if (
this.options.direction !== 'bottom'
&& dropdownHeight + dropdownTop > windowHeight + scrollTop
// only change direction if there is more space on the other side
&& windowHeight / 2 < dropdownTop - scrollTop
) {
this.sandbox.dom.addClass(this.$dropdownContainer, constants.dropdownTopClass);
dropdownMaxHeight = dropdownHeight + this.$dropdownContainer.offset().top;
}

this.$dropdownContainer.css({maxHeight: dropdownMaxHeight - this.options.dropdownPadding + 'px'});
},

// hide dropDown
Expand All @@ -40755,7 +40763,6 @@ define('__component__$select@husky',[], function() {
this.sandbox.dom.off(this.sandbox.dom.window, 'click.dropdown.' + this.options.instanceName);
}
}
this.sandbox.logger.log('hide dropdown ' + this.options.instanceName);
this.sandbox.dom.addClass(this.$dropdownContainer, 'hidden');
this.dropdownVisible = false;
return true;
Expand Down
2 changes: 1 addition & 1 deletion dist/husky.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/husky.min.js

Large diffs are not rendered by default.

29 changes: 18 additions & 11 deletions husky_components/select/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @param {Boolean} [options.isNative] should use native select
* @param {Boolean} [options.showToolTip] Show tool-tip on hover - only works for single-selects
* @param {Array} [options.defaultValue] Array of default items that should be selected if no item has been preselected
* @param {Number} [options.dropdownPadding] The amount of padding on top or bottom of the dropdown list
*/

define([], function() {
Expand Down Expand Up @@ -78,7 +79,8 @@ define([], function() {
showToolTip: false,
translations: translations,
isNative: false,
defaultValue: null
defaultValue: null,
dropdownPadding: 0,
},

constants = {
Expand Down Expand Up @@ -1189,24 +1191,30 @@ define([], function() {
return;
}

this.sandbox.logger.log('show dropdown ' + this.options.instanceName);
this.sandbox.dom.removeClass(this.$dropdownContainer, 'hidden');
this.sandbox.dom.on(this.sandbox.dom.window, 'click.dropdown.' + this.options.instanceName, this.hideDropDown.bind(this));
this.dropdownVisible = true;

this.sandbox.dom.removeClass(this.$dropdownContainer, constants.dropdownTopClass);
var ddHeight = this.sandbox.dom.height(this.$dropdownContainer),
ddTop = this.sandbox.dom.offset(this.$dropdownContainer).top,
var dropdownHeight = this.sandbox.dom.height(this.$dropdownContainer),
dropdownTop = this.sandbox.dom.offset(this.$dropdownContainer).top,
windowHeight = this.sandbox.dom.height(this.sandbox.dom.window),
scrollTop = this.sandbox.dom.scrollTop(this.sandbox.dom.window);
scrollTop = this.sandbox.dom.scrollTop(this.sandbox.dom.window),
dropdownMaxHeight = windowHeight - dropdownTop;

if (this.options.direction === 'top') {
this.sandbox.dom.addClass(this.$dropdownContainer, constants.dropdownTopClass);
} else if (this.options.direction !== 'bottom') {
// check if dropdown container overlaps bottom of browser
if (ddHeight + ddTop > windowHeight + scrollTop) {
this.sandbox.dom.addClass(this.$dropdownContainer, constants.dropdownTopClass);
}
} else if (
this.options.direction !== 'bottom'
&& dropdownHeight + dropdownTop > windowHeight + scrollTop
// only change direction if there is more space on the other side
&& windowHeight / 2 < dropdownTop - scrollTop
) {
this.sandbox.dom.addClass(this.$dropdownContainer, constants.dropdownTopClass);
dropdownMaxHeight = dropdownHeight + this.$dropdownContainer.offset().top;
}

this.$dropdownContainer.css({maxHeight: dropdownMaxHeight - this.options.dropdownPadding + 'px'});
},

// hide dropDown
Expand All @@ -1218,7 +1226,6 @@ define([], function() {
this.sandbox.dom.off(this.sandbox.dom.window, 'click.dropdown.' + this.options.instanceName);
}
}
this.sandbox.logger.log('hide dropdown ' + this.options.instanceName);
this.sandbox.dom.addClass(this.$dropdownContainer, 'hidden');
this.dropdownVisible = false;
return true;
Expand Down
3 changes: 2 additions & 1 deletion scss/modules/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@
min-width: 100%;
position: absolute;
top: 20px;
left: 0px;
left: 0;
margin-top: 5px;
background-color: #FFF;
border: 1px solid $grayLighter;
z-index: 2000;
border-radius: $borderRadius;
overflow: auto;

.divider {
max-width: 100%;
Expand Down

0 comments on commit 833b883

Please sign in to comment.