input pill: Add convert_to_pill_on_enter option.

This is needed for us to support "search for..."
(i.e. operand = "search") terms being displayed
as text instead of search pills, once we convert
search to search pills.
This commit is contained in:
evykassirer 2024-06-25 16:40:09 -07:00 committed by Tim Abbott
parent 141e08f587
commit 5211488b9c
1 changed files with 7 additions and 1 deletions

View File

@ -32,6 +32,7 @@ type InputPillCreateOptions<T> = {
$container: JQuery;
pill_config?: InputPillConfig | undefined;
split_text_on_comma?: boolean;
convert_to_pill_on_enter?: boolean;
create_item_from_text: (
text: string,
existing_items: InputPillItem<T>[],
@ -57,6 +58,7 @@ type InputPillStore<T> = {
onPillRemove?: (pill: InputPill<T>) => void;
createPillonPaste?: () => void;
split_text_on_comma: boolean;
convert_to_pill_on_enter: boolean;
};
type InputPillRenderingDetails = {
@ -99,6 +101,7 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
create_item_from_text: opts.create_item_from_text,
get_text_from_item: opts.get_text_from_item,
split_text_on_comma: opts.split_text_on_comma ?? true,
convert_to_pill_on_enter: opts.convert_to_pill_on_enter ?? true,
};
// a dictionary of internal functions. Some of these are exposed as well,
@ -319,7 +322,10 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
{
store.$parent.on("keydown", ".input", function (this: HTMLElement, e) {
if (keydown_util.is_enter_event(e)) {
// `convert_to_pill_on_enter = false` allows some pill containers,
// which don't convert all of their text input to pills, to have
// their own custom handlers of enter events.
if (keydown_util.is_enter_event(e) && store.convert_to_pill_on_enter) {
// regardless of the value of the input, the ENTER keyword
// should be ignored in favor of keeping content to one line
// always.