|
1 | 1 | <template>
|
2 |
| - <Combobox v-model="selectedAction"> |
| 2 | + <Combobox v-model="selectedAction" :nullable="true"> |
3 | 3 | <ComboboxInput
|
4 | 4 | ref="inputBox"
|
5 | 5 | class="input input-bordered mt-2 w-full"
|
6 | 6 | @input="inputValue = $event.target.value"
|
7 | 7 | ></ComboboxInput>
|
8 | 8 | <ComboboxOptions
|
9 | 9 | class="card dropdown-content absolute max-h-48 w-full overflow-y-scroll rounded-lg border border-base-300 bg-base-100"
|
| 10 | + :unmount="false" |
10 | 11 | >
|
11 | 12 | <ComboboxOption
|
12 | 13 | v-for="(action, idx) in filteredActions"
|
|
68 | 69 | },
|
69 | 70 | });
|
70 | 71 |
|
71 |
| - const selectedAction = useVModel(props, "modelValue"); |
| 72 | + const emit = defineEmits(["update:modelValue", "actionSelected"]); |
| 73 | + const selectedAction = ref(null); |
72 | 74 |
|
73 | 75 | const inputValue = ref("");
|
74 | 76 | const inputBox = ref();
|
75 | 77 | const inputBoxButton = ref();
|
76 | 78 | const { focused: inputBoxFocused } = useFocus(inputBox);
|
77 | 79 |
|
78 |
| - const emit = defineEmits(["update:modelValue", "quickSelect"]); |
79 |
| -
|
80 | 80 | const revealActions = () => {
|
81 | 81 | unrefElement(inputBoxButton).click();
|
82 | 82 | };
|
83 | 83 |
|
84 |
| - watch(inputBoxFocused, () => { |
85 |
| - if (inputBoxFocused.value) revealActions(); |
| 84 | + watch(inputBoxFocused, val => { |
| 85 | + if (val) revealActions(); |
86 | 86 | else inputValue.value = "";
|
87 | 87 | });
|
88 | 88 |
|
89 | 89 | watch(inputValue, (val, oldVal) => {
|
90 | 90 | if (!oldVal) {
|
91 | 91 | const action = props.actions?.find(v => v.shortcut === val);
|
92 | 92 | if (action) {
|
93 |
| - emit("quickSelect", action); |
| 93 | + emit("actionSelected", action); |
| 94 | + inputBoxFocused.value = false; |
94 | 95 | }
|
95 | 96 | }
|
96 | 97 | });
|
97 | 98 |
|
| 99 | + watch(selectedAction, val => { |
| 100 | + if (val) { |
| 101 | + emit("actionSelected", val); |
| 102 | + selectedAction.value = null; |
| 103 | + } |
| 104 | + }); |
| 105 | +
|
98 | 106 | const filteredActions = computed(() => {
|
99 | 107 | const searchTerm = inputValue.value.toLowerCase();
|
100 | 108 | return (props.actions || []).filter(action => {
|
|
0 commit comments