Skip to content

Commit a7db68e

Browse files
committed
Adjust remove-button styling for single-select
and add an example.
1 parent ea2e931 commit a7db68e

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

examples/plugins.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ <h2>Plugin: "remove_button"</h2>
3131
<label for="input-tags2">Tags:</label>
3232
<input type="text" disabled id="input-tags2" class="input-tags demo-default" value="awesome,neat">
3333
</div>
34+
<div class="control-group">
35+
<label for="input-tags">Tags:</label>
36+
<input type="text" id="input-tags3" class="input-tags2 demo-default" value="awesome">
37+
</div>
3438
<script>
3539
$('.input-tags').selectize({
3640
plugins: ['remove_button'],
@@ -45,6 +49,14 @@ <h2>Plugin: "remove_button"</h2>
4549
return confirm(values.length > 1 ? 'Are you sure you want to remove these ' + values.length + ' items?' : 'Are you sure you want to remove "' + values[0] + '"?');
4650
}
4751
});
52+
53+
// single selection
54+
$('.input-tags2').selectize({
55+
plugins: ['remove_button'],
56+
persist: true,
57+
create: true,
58+
maxItems: 1
59+
});
4860
</script>
4961
</div>
5062

src/plugins/remove_button/plugin.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ Selectize.define('remove_button', function(options) {
1818
options = $.extend({
1919
label : '&times;',
2020
title : 'Remove',
21-
className : 'remove',
21+
className : this.settings.mode === 'single' ? 'remove-single' : 'remove',
2222
append : true
2323
}, options);
2424

2525
var self = this;
26-
if (this.settings.mode === 'single') {
27-
options.className = options.className || 'remove-single';
28-
}
29-
3026
var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>';
3127

3228
/**

src/plugins/remove_button/plugin.less

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,22 @@
3434
.disabled [data-value] .remove {
3535
border-left-color: lighten(desaturate(@selectize-color-item-border, 100%), @selectize-lighten-disabled-item-border);
3636
}
37-
.remove-single {
37+
[data-value] .remove-single {
3838
position: absolute;
39-
right: 0;
40-
top: 0;
41-
font-size: 23px;
39+
right: @selectize-padding-x - 2px;
40+
top: -1px;
41+
display: flex;
42+
justify-content: center;
43+
align-items: center;
44+
font-size: @selectize-line-height;
45+
color: lighten(@selectize-arrow-color, 30%);
46+
text-shadow: 0 1px 0 rgba(0,0,0,0.1);
47+
&:hover:not(:active) {
48+
color: transparent;
49+
text-shadow: 0 0 1px @selectize-arrow-color;
50+
}
51+
&:hover:active {
52+
text-shadow: none;
53+
}
4254
}
4355
}

0 commit comments

Comments
 (0)