Skip to content

Custom class for label element #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ $('select').selectric({
* replaced in this method.
*/
labelBuilder: '{text}',

/*
* Type: String
* Description: Custom class for label element
*/
labelClass: 'label',

/*
* Type: Boolean
Expand Down
3 changes: 2 additions & 1 deletion src/jquery.selectric.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
var items = $('<div/>', { 'class': _this.classes.items, 'tabindex': -1 });
var itemsScroll = $('<div/>', { 'class': _this.classes.scroll });
var wrapper = $('<div/>', { 'class': _this.classes.prefix, 'html': _this.options.arrowButtonMarkup });
var label = $('<span/>', { 'class': 'label' });
var label = $('<span/>', { 'class': _this.options.labelClass });
var outerWrapper = _this.$element.wrap('<div/>').parent().append(wrapper.prepend(label), items, input);
var hideSelectWrapper = $('<div/>', { 'class': _this.classes.hideselect });

Expand Down Expand Up @@ -1090,6 +1090,7 @@
optionsItemBuilder : '{text}', // function(itemData, element, index)
labelBuilder : '{text}', // function(currItem)
listBuilder : false, // function(items)
labelClass : 'label',
keys : {
previous : [37, 38], // Left / Up
next : [39, 40], // Right / Down
Expand Down
14 changes: 10 additions & 4 deletions test/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('basic suite', function() {
$('.selectric-input').val('banana').trigger('input');
$('.selectric-items').find('.highlighted').lenght;
expect($('.selectric-items').find('.highlighted').length).toBe(0);
});
});

it('should search alternative text', function () {
select.find('option:eq(6)').attr('data-alt', 'alt blackberry');
Expand Down Expand Up @@ -125,21 +125,21 @@ describe('basic suite', function() {
$('.selectric-input').val('another berry').trigger('input');
$('.selectric-items').find('.highlighted').click();
expect(select.val()).toBe('blackberry');
});
});

it('should skip blank alternative text', function () {
select.find('option:eq(6)').attr('data-alt', '');
select.selectric('refresh');
$('.selectric-input').val('a text that does not exist').trigger('input');
expect($('.selectric-items').find('.highlighted').length).toBe(0);
});
});

it('should skip blank alternative text with separator', function () {
select.find('option:eq(6)').attr('data-alt', '|');
select.selectric('refresh');
$('.selectric-input').val('a text that does not exist').trigger('input');
expect($('.selectric-items').find('.highlighted').length).toBe(0);
});
});

it('highlight() should return undefined if index is undefined', function () {
expect(select.data('selectric').highlight(undefined)).toBe(undefined);
Expand Down Expand Up @@ -340,4 +340,10 @@ describe('basic suite', function() {
$('.selectric-items').find('li:eq(4)').click();
expect($('.selectric-wrapper').find('.label').text()).toBe('BANANA');
});

it('should be not default class on the label when using labelClass option', function() {
select.selectric({ labelClass: 'custom-label-class' });

expect(select.data('selectric').elements.wrapper.children().hasClass('custom-label-class')).toBe(true);
});
});