[Bug]: Enter key won't add item when custom `option_create` is used
ocv-robert opened this issue · 1 comments
ocv-robert commented
Bug description
I create a TomSelect with the following options:
plugins: {
remove_button: {
title: 'Remove'
}
},
persist: false,
copyClassesToDropdown: false,
closeAfterSelect: false,
addPrecedence: true,
controlInput: '<input type="text" autocomplete="off" tabindex="0" class="tom-select-input w-full">',
render: {
option: (data, escape) => {
return `<div class="p-2.5 aria-selected:bg-indigo-600 aria-selected:text-white cursor-pointer">${escape(data.text)}</div>`
},
option_create: (data, escape) => {
return `<div class="p-2.5 aria-selected:bg-indigo-600 aria-selected:text-white cursor-pointer">Add <span class="font-semibold">${escape(data.input)}</span></div>`
},
item: (data, escape) => {
return `<div class="rounded-md ml-2.5 p-2.5 py-1 text-xs whitespace-nowrap bg-indigo-600 text-white">${escape(data.text)}</div>`
},
no_results: () => {
return '<div class="p-2.5">No results found.</div>'
}
}
And seemingly just by providing a custom option_create
function, it breaks the functionality where Enter adds the item to the field. Tab still works (with createOnBlur
enabled):
Removing the custom option_create
function restores the functionality, but looks bad due to the lack of styling:
Expected behavior
Enter with the custom option_create
function should still work.
Steps to reproduce
https://jsfiddle.net/ag3ob62s/1/
Additional context
- OS: macOS Sonoma 14.3
- Browser: Chrome 122.0.6261.69
- Device: 14" MacBook Pro M2
ocv-robert commented
Wow, apparently it's required that the returned element has the create
class applied to it? 🤯
Lines 884 to 889 in 69180fa