Skip to content
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
27 changes: 15 additions & 12 deletions src/plugins/remove_button/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,28 @@ import { TomOption, TomItem } from '../../types/index.ts';
import { RBOptions } from './types.ts';

export default function(this:TomSelect, userOptions:RBOptions) {
const self = this;

const options = Object.assign({
label : '×',
title : 'Remove',
className : 'remove',
append : true
tabindex : -1,
role : 'button',
html : (data:RBOptions) => {
const el = document.createElement('div');

el.className = data.className || '';
el.title = data.title || '';
el.setAttribute('role', data.role || 'button');
el.tabIndex = data.tabindex ?? -1;
el.textContent = data.label || '';

return el;
}
}, userOptions);


//options.className = 'remove-single';
var self = this;

// override the render method to add remove button to each item
if( !options.append ){
return;
}

var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>';

self.hook('after','setupTemplates',() => {

var orig_render_item = self.settings.render.item;
Expand All @@ -47,7 +50,7 @@ export default function(this:TomSelect, userOptions:RBOptions) {

var item = getDom(orig_render_item.call(self, data, escape)) as TomItem;

var close_button = getDom(html);
var close_button = getDom(options.html(options));
item.appendChild(close_button);

addEvent(close_button,'mousedown',(evt) => {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/remove_button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ export type RBOptions = {
label ?: string,
title ?: string,
className ?: string,
append ?: boolean
tabindex ?: number,
role ?: string,
html ?: (data: RBOptions) => string,
};