Browse Source

Iteration on multiselect

pull/2034/head
jlukic 9 years ago
parent
commit
5513680a9f
3 changed files with 95 additions and 30 deletions
  1. 80
      src/definitions/modules/dropdown.js
  2. 29
      src/definitions/modules/dropdown.less
  3. 16
      src/themes/default/modules/dropdown.variables

80
src/definitions/modules/dropdown.js

@ -278,6 +278,9 @@ $.fn.dropdown = function(parameters) {
} }
if( module.can.show() && !module.is.active() ) { if( module.can.show() && !module.is.active() ) {
module.debug('Showing dropdown'); module.debug('Showing dropdown');
if(module.is.multiple()) {
module.filterActive();
}
module.animate.show(function() { module.animate.show(function() {
if( module.can.click() ) { if( module.can.click() ) {
module.bind.intent(); module.bind.intent();
@ -357,6 +360,11 @@ $.fn.dropdown = function(parameters) {
.on('blur' + eventNamespace, selector.search, module.event.searchBlur) .on('blur' + eventNamespace, selector.search, module.event.searchBlur)
.on('click' + eventNamespace, selector.text, module.event.searchTextFocus) .on('click' + eventNamespace, selector.text, module.event.searchTextFocus)
; ;
if(module.is.multiple()) {
$module
.on('click' + eventNamespace, module.event.click)
;
}
} }
else { else {
if(settings.on == 'click') { if(settings.on == 'click') {
@ -450,6 +458,9 @@ $.fn.dropdown = function(parameters) {
.not($results) .not($results)
.addClass(className.filtered) .addClass(className.filtered)
; ;
if(module.is.multiple()) {
module.filterActive();
}
module.verbose('Selecting first non-filtered element'); module.verbose('Selecting first non-filtered element');
module.remove.selectedItem(); module.remove.selectedItem();
$item $item
@ -466,6 +477,12 @@ $.fn.dropdown = function(parameters) {
} }
}, },
filterActive: function() {
$item.filter('.' + className.active)
.addClass(className.filtered)
;
},
focusSearch: function() { focusSearch: function() {
if( module.is.search() ) { if( module.is.search() ) {
$search $search
@ -483,7 +500,7 @@ $.fn.dropdown = function(parameters) {
: $activeItem, : $activeItem,
hasSelected = ($selectedItem.size() > 0) hasSelected = ($selectedItem.size() > 0)
; ;
if(hasSelected) {
if(hasSelected && !module.is.multiple()) {
module.event.item.click.call($selectedItem); module.event.item.click.call($selectedItem);
module.remove.filteredItem(); module.remove.filteredItem();
} }
@ -493,6 +510,12 @@ $.fn.dropdown = function(parameters) {
}, },
event: { event: {
click: function(event) {
// focus search
if($(event.target).is($module) && !(document.activeElement === $search[0])) {
$search.focus();
}
},
// prevents focus callback from occuring on mousedown // prevents focus callback from occuring on mousedown
mousedown: function() { mousedown: function() {
activated = true; activated = true;
@ -1243,12 +1266,16 @@ $.fn.dropdown = function(parameters) {
selected: function(value) { selected: function(value) {
var var
$selectedItem = module.get.item(value), $selectedItem = module.get.item(value),
isMultiple = module.is.multiple(),
shouldAnimate = (isMultiple && $selectedItem.length == 1),
selectedText, selectedText,
selectedValue selectedValue
; ;
if($selectedItem && !$selectedItem.hasClass(className.active) ) { if($selectedItem && !$selectedItem.hasClass(className.active) ) {
module.debug('Setting selected menu item to', $selectedItem); module.debug('Setting selected menu item to', $selectedItem);
module.remove.activeItem();
if(!module.is.multiple()) {
module.remove.activeItem();
}
module.remove.selectedItem(); module.remove.selectedItem();
$selectedItem $selectedItem
.addClass(className.active) .addClass(className.active)
@ -1259,8 +1286,8 @@ $.fn.dropdown = function(parameters) {
; ;
selectedText = module.get.choiceText($selected); selectedText = module.get.choiceText($selected);
selectedValue = module.get.choiceValue($selected, selectedText); selectedValue = module.get.choiceValue($selected, selectedText);
if(module.is.multiple()) {
module.add.label(selectedValue, selectedText);
if(isMultiple) {
module.add.label(selectedValue, selectedText, shouldAnimate);
} }
else { else {
module.set.text(selectedText); module.set.text(selectedText);
@ -1274,18 +1301,30 @@ $.fn.dropdown = function(parameters) {
}, },
add: { add: {
label: function(value, text) {
label: function(value, text, shouldAnimate) {
var var
$label = $('<a />') $label = $('<a />')
.addClass(className.label) .addClass(className.label)
.data('value', value)
.attr('data-value', value)
.html(text + '<i class="delete icon"></i>') .html(text + '<i class="delete icon"></i>')
; ;
if(settings.label.variation) { if(settings.label.variation) {
$label.addClass(settings.label.variation); $label.addClass(settings.label.variation);
} }
module.debug('Adding selection label', $label);
$label.insertBefore($search);
if(shouldAnimate) {
module.debug('Animating in label', $label);
$label
.addClass(className.hidden)
.insertBefore($search)
.transition(settings.label.transition, settings.label.duration)
;
}
else {
module.debug('Adding selection label', $label);
$label
.insertBefore($search)
;
}
} }
}, },
@ -1308,6 +1347,15 @@ $.fn.dropdown = function(parameters) {
selectedItem: function() { selectedItem: function() {
$item.removeClass(className.selected); $item.removeClass(className.selected);
}, },
label: function(value) {
$module
.find(selector.label)
.filter('[data-value="' + value +'"]')
.transition(settings.label.transition, settings.label.duration, function() {
$(this).remove();
})
;
},
tabbable: function() { tabbable: function() {
if( module.has.search() ) { if( module.has.search() ) {
module.debug('Searchable dropdown initialized'); module.debug('Searchable dropdown initialized');
@ -1424,7 +1472,9 @@ $.fn.dropdown = function(parameters) {
? callback ? callback
: function(){} : function(){}
; ;
module.set.scrollPosition(module.get.activeItem(), true);
if(!module.is.multiple()) {
module.set.scrollPosition(module.get.activeItem(), true);
}
module.verbose('Doing menu show animation', $currentMenu); module.verbose('Doing menu show animation', $currentMenu);
if( module.is.hidden($currentMenu) || module.is.animating($currentMenu) ) { if( module.is.hidden($currentMenu) || module.is.animating($currentMenu) ) {
@ -1786,7 +1836,9 @@ $.fn.dropdown.settings = {
sortSelect : false, sortSelect : false,
label: { label: {
variation: false
transition : 'horizontal flip',
duration : 250,
variation : false
}, },
allowCategorySelection : false, allowCategorySelection : false,
@ -1798,10 +1850,10 @@ $.fn.dropdown.settings = {
touch : 50 touch : 50
}, },
forceSelection: true,
forceSelection : true,
transition : 'auto',
duration : 250,
transition : 'auto',
duration : 250,
/* Callbacks */ /* Callbacks */
onNoResults : function(searchTerm){}, onNoResults : function(searchTerm){},
@ -1833,6 +1885,7 @@ $.fn.dropdown.settings = {
dropdown : '.ui.dropdown', dropdown : '.ui.dropdown',
input : '> input[type="hidden"], > select', input : '> input[type="hidden"], > select',
item : '.item', item : '.item',
label : '> .label',
menu : '.menu', menu : '.menu',
menuIcon : '.dropdown.icon', menuIcon : '.dropdown.icon',
search : 'input.search, .menu > .search > input', search : 'input.search, .menu > .search > input',
@ -1845,6 +1898,7 @@ $.fn.dropdown.settings = {
disabled : 'disabled', disabled : 'disabled',
dropdown : 'ui dropdown', dropdown : 'ui dropdown',
filtered : 'filtered', filtered : 'filtered',
hidden : 'hidden transition',
label : 'ui label', label : 'ui label',
loading : 'loading', loading : 'loading',
menu : 'menu', menu : 'menu',

29
src/definitions/modules/dropdown.less

@ -590,18 +590,28 @@ select.ui.dropdown {
Multiple Multiple
---------------*/ ---------------*/
/* Multiple Search Selection */
/* Multiple Selection */
.ui.multiple.dropdown { .ui.multiple.dropdown {
cursor: auto;
padding: @multipleSelectionTopPadding @multipleSelectionRightPadding @multipleSelectionBottomPadding @multipleSelectionLeftPadding; padding: @multipleSelectionTopPadding @multipleSelectionRightPadding @multipleSelectionBottomPadding @multipleSelectionLeftPadding;
} }
.ui.multiple.dropdown .menu {
cursor: auto;
}
/* Multiple Search Selection */
.ui.multiple.search.dropdown {
cursor: text;
}
/* Selection Label */ /* Selection Label */
.ui.multiple.dropdown > .label { .ui.multiple.dropdown > .label {
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
padding: @labelPadding; padding: @labelPadding;
margin: 0em @labelSpacing @labelSpacing 0em;
margin: (@labelVerticalSpacing / 2) @labelHorizontalSpacing (@labelVerticalSpacing / 2) 0em;
}
.ui.multiple.dropdown > .label .delete {
opacity: 0.4;
} }
/* Prompt Text */ /* Prompt Text */
@ -616,19 +626,14 @@ select.ui.dropdown {
.ui.multiple.selection.dropdown > input.search { .ui.multiple.selection.dropdown > input.search {
position: static; position: static;
padding: 0; padding: 0;
width: auto;
margin-top: @searchSelectionLineHeightOffset;
padding-top: @labelVerticalPadding;
}
.ui.multiple.selection.dropdown > .label + input.search {
margin-left: 0.5em;
width: 5em;
margin: @multipleSelectionSearchMargin;
} }
/* Dropdown Icon */ /* Dropdown Icon */
.ui.multiple.selection.dropdown .dropdown.icon { .ui.multiple.selection.dropdown .dropdown.icon {
padding: 0em;
margin: 0em;
margin: 0em -@labelHorizontalPadding 0em 0em;
padding: @labelPadding;
} }

16
src/themes/default/modules/dropdown.variables

@ -114,7 +114,7 @@
@selectionMinWidth: 180px; @selectionMinWidth: 180px;
@selectionBackground: @white; @selectionBackground: @white;
@selectionDisplay: inline-block; @selectionDisplay: inline-block;
@selectionItemDivider: 1px solid @borderColor;
@selectionItemDivider: 1px solid rgba(0, 0, 0, 0.05);
@selectionVerticalPadding: 0.8em; @selectionVerticalPadding: 0.8em;
@selectionHorizontalPadding: 1.1em; @selectionHorizontalPadding: 1.1em;
@selectionIconDistance: 2em; @selectionIconDistance: 2em;
@ -205,15 +205,21 @@
/* Multiple */ /* Multiple */
@labelVerticalPadding: 0.4285em; @labelVerticalPadding: 0.4285em;
@labelSize: @relativeSmall;
@labelHorizontalPadding: @relativeMini; @labelHorizontalPadding: @relativeMini;
@labelPadding: @labelVerticalPadding @labelHorizontalPadding; @labelPadding: @labelVerticalPadding @labelHorizontalPadding;
@labelSpacing: 0.21428em;
@multipleSelectionTopPadding: (@selectionVerticalPadding - @labelVerticalPadding);
@labelHorizontalSpacing: 0.5em;
@labelVerticalSpacing: 0.5em;
/* This is calculated from @selectionPadding - @labelSize * labelPadding */
@multipleSelectionTopPadding: 0.2857em;
@multipleSelectionRightPadding: @selectionIconDistance; @multipleSelectionRightPadding: @selectionIconDistance;
@multipleSelectionBottomPadding: @selectionTopPadding - @labelSpacing;
@multipleSelectionBottomPadding: @multipleSelectionTopPadding;
@multipleSelectionLeftPadding: (@selectionHorizontalPadding - @labelHorizontalPadding); @multipleSelectionLeftPadding: (@selectionHorizontalPadding - @labelHorizontalPadding);
@multipleSearchOffset: (@labelVerticalPadding - @searchSelectionLineHeightOffset);
@multipleSelectionSearchMargin: 0.4em 0em 0.4em 0.5em;
/* Inline */ /* Inline */
@inlineIconMargin: 0em 0.5em 0em 0.25em; @inlineIconMargin: 0em 0.5em 0em 0.25em;

Loading…
Cancel
Save