Upload folder using huggingface_hub
Browse files
6.2.0/dropdown/shared/Dropdown.svelte
CHANGED
|
@@ -3,10 +3,10 @@
|
|
| 3 |
import { BlockTitle, IconButtonWrapper } from "@gradio/atoms";
|
| 4 |
import { DropdownArrow } from "@gradio/icons";
|
| 5 |
import { handle_filter, handle_shared_keys } from "./utils";
|
| 6 |
-
import
|
| 7 |
-
SelectData,
|
| 8 |
-
KeyUpData,
|
| 9 |
-
CustomButton as CustomButtonType
|
| 10 |
} from "@gradio/utils";
|
| 11 |
import { tick } from "svelte";
|
| 12 |
|
|
@@ -79,6 +79,9 @@
|
|
| 79 |
return ["", null];
|
| 80 |
}
|
| 81 |
});
|
|
|
|
|
|
|
|
|
|
| 82 |
let initialized = $state(false);
|
| 83 |
let disabled = $derived(!interactive);
|
| 84 |
|
|
@@ -96,6 +99,7 @@
|
|
| 96 |
|
| 97 |
let [_input_text, _value] = choices[selected_index];
|
| 98 |
input_text = _input_text;
|
|
|
|
| 99 |
value = _value;
|
| 100 |
on_select?.({
|
| 101 |
index: selected_index,
|
|
@@ -104,6 +108,7 @@
|
|
| 104 |
});
|
| 105 |
show_options = false;
|
| 106 |
active_index = null;
|
|
|
|
| 107 |
filter_input.blur();
|
| 108 |
}
|
| 109 |
|
|
@@ -118,7 +123,13 @@
|
|
| 118 |
input_text =
|
| 119 |
choices_names[choices_values.indexOf(value as string | number)];
|
| 120 |
} else {
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
show_options = false;
|
| 124 |
active_index = null;
|
|
@@ -137,6 +148,7 @@
|
|
| 137 |
filtered_indices
|
| 138 |
);
|
| 139 |
if (e.key === "Enter") {
|
|
|
|
| 140 |
if (active_index !== null) {
|
| 141 |
selected_index = active_index;
|
| 142 |
value = choices_values[active_index];
|
|
|
|
| 3 |
import { BlockTitle, IconButtonWrapper } from "@gradio/atoms";
|
| 4 |
import { DropdownArrow } from "@gradio/icons";
|
| 5 |
import { handle_filter, handle_shared_keys } from "./utils";
|
| 6 |
+
import {
|
| 7 |
+
type SelectData,
|
| 8 |
+
type KeyUpData,
|
| 9 |
+
type CustomButton as CustomButtonType
|
| 10 |
} from "@gradio/utils";
|
| 11 |
import { tick } from "svelte";
|
| 12 |
|
|
|
|
| 79 |
return ["", null];
|
| 80 |
}
|
| 81 |
});
|
| 82 |
+
// Use last_typed_value to track when the user has typed
|
| 83 |
+
// on_blur we only want to update value if the user has typed
|
| 84 |
+
let last_typed_value = input_text;
|
| 85 |
let initialized = $state(false);
|
| 86 |
let disabled = $derived(!interactive);
|
| 87 |
|
|
|
|
| 99 |
|
| 100 |
let [_input_text, _value] = choices[selected_index];
|
| 101 |
input_text = _input_text;
|
| 102 |
+
last_typed_value = input_text;
|
| 103 |
value = _value;
|
| 104 |
on_select?.({
|
| 105 |
index: selected_index,
|
|
|
|
| 108 |
});
|
| 109 |
show_options = false;
|
| 110 |
active_index = null;
|
| 111 |
+
on_input?.();
|
| 112 |
filter_input.blur();
|
| 113 |
}
|
| 114 |
|
|
|
|
| 123 |
input_text =
|
| 124 |
choices_names[choices_values.indexOf(value as string | number)];
|
| 125 |
} else {
|
| 126 |
+
if (choices_names.includes(input_text)) {
|
| 127 |
+
selected_index = choices_names.indexOf(input_text);
|
| 128 |
+
value = choices_values[selected_index];
|
| 129 |
+
} else if (input_text !== last_typed_value) {
|
| 130 |
+
value = input_text;
|
| 131 |
+
selected_index = null;
|
| 132 |
+
}
|
| 133 |
}
|
| 134 |
show_options = false;
|
| 135 |
active_index = null;
|
|
|
|
| 148 |
filtered_indices
|
| 149 |
);
|
| 150 |
if (e.key === "Enter") {
|
| 151 |
+
last_typed_value = input_text;
|
| 152 |
if (active_index !== null) {
|
| 153 |
selected_index = active_index;
|
| 154 |
value = choices_values[active_index];
|