Fix search bar behaviour (step 5)

This commit is contained in:
Joshua Boniface 2025-03-02 14:38:43 -05:00
parent c1ddbd1f3f
commit 1d26e0338f

View File

@ -4,9 +4,14 @@
<button <button
class="btn btn-outline-secondary list-toggle-btn" class="btn btn-outline-secondary list-toggle-btn"
@click="toggleList" @click="toggleList"
:class="{ 'active': showList }" :class="{
'active': showList,
'filtering': showList && isFilterActive
}"
:title="showList ? (isFilterActive ? 'Show all VMs' : 'Filter VMs') : 'List VMs'"
> >
<i class="fas fa-list"></i> List VMs <i class="fas" :class="showList && isFilterActive ? 'fa-filter' : 'fa-list'"></i>
{{ showList ? (isFilterActive ? 'Filtering' : 'All VMs') : 'List VMs' }}
</button> </button>
<div class="search-box"> <div class="search-box">
@ -255,14 +260,23 @@ const handleSearchClick = () => {
// Toggle the VM list // Toggle the VM list
const toggleList = () => { const toggleList = () => {
// If the list is already open, toggle filtering instead of closing
if (props.showList) { if (props.showList) {
// If we're closing the list, save the search text // Toggle filtering mode
if (props.modelValue) { isFilterActive.value = !isFilterActive.value;
searchText.value = props.modelValue;
// Save to localStorage // If we're turning filtering on, make sure the search text is applied
localStorage.setItem('vmSearchText', props.modelValue); if (isFilterActive.value && searchText.value) {
inputValue.value = searchText.value;
emit('update:modelValue', searchText.value);
} }
} else {
// No need to emit toggle-list since we're not closing the list
return;
}
// If the list is closed, open it without filtering
if (!props.showList) {
// If we're opening the list, deactivate filtering // If we're opening the list, deactivate filtering
isFilterActive.value = false; isFilterActive.value = false;
@ -558,6 +572,12 @@ const scrollToSelectedVM = () => {
color: white; color: white;
} }
.list-toggle-btn.filtering {
background-color: #0d6efd;
color: white;
border-color: #0d6efd;
}
.filter-dropdown { .filter-dropdown {
position: relative; position: relative;
} }