Skip to content

Commit cc641da

Browse files
committed
Show 'No Results Found' message when no tags match search
- Add .no-tags-message style to _cases.scss - Add toggleNoTagsMessage function to searchInputHandler.js - Show message in case-studies-page index.html when no tags are visible
1 parent 8192603 commit cc641da

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

website/modules/asset/ui/src/scss/_cases.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@
147147
}
148148
}
149149

150+
.no-tags-message {
151+
display: none;
152+
margin: 0;
153+
color: $gray-300;
154+
@include font-settings(11px, 140%, $font-weight-medium);
155+
}
156+
150157
// Pagination
151158
.pagination-container {
152159
margin-top: 3rem;

website/modules/asset/ui/src/searchInputHandler.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ const removePreviousHandler = (input) => {
44
}
55
};
66

7+
const toggleNoTagsMessage = (
8+
tagItems,
9+
hasVisible,
10+
parentSelector = '.filter-section',
11+
) => {
12+
const parent = tagItems[0]?.closest(parentSelector);
13+
const messageEl = parent?.querySelector('.no-tags-message');
14+
if (messageEl) {
15+
if (hasVisible) {
16+
messageEl.style.display = 'none';
17+
} else {
18+
messageEl.style.display = 'block';
19+
}
20+
}
21+
};
22+
723
const getFilterValue = (input) => {
824
return input.value.trim().toLowerCase();
925
};
@@ -12,15 +28,20 @@ const getTagItems = (container, tagSelector) => {
1228
return container.querySelectorAll(tagSelector);
1329
};
1430

15-
const filterTagItems = (tagItems, filterValue, getTagLabel) => {
31+
const filterTagItems = (tagItems, filterValue, getTagLabel, parentSelector) => {
32+
let hasVisible = false;
33+
1634
tagItems.forEach((tagItem) => {
1735
const tagLabel = getTagLabel(tagItem);
1836
if (tagLabel.includes(filterValue)) {
1937
tagItem.style.display = '';
38+
hasVisible = true;
2039
} else {
2140
tagItem.style.display = 'none';
2241
}
2342
});
43+
44+
toggleNoTagsMessage(tagItems, hasVisible, parentSelector);
2445
};
2546

2647
const handleTagSearch = (
@@ -34,7 +55,7 @@ const handleTagSearch = (
3455
if (!container) return;
3556

3657
const tagItems = getTagItems(container, tagSelector);
37-
filterTagItems(tagItems, filterValue, getTagLabel);
58+
filterTagItems(tagItems, filterValue, getTagLabel, containerSelector);
3859
};
3960

4061
const createTagSearchHandler = (

website/modules/case-studies-page/views/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
</li>
148148
{% endif %} {% endfor %}
149149
</ul>
150+
<p class="no-tags-message">No Results Found</p>
150151
</div>
151152
{% endif %} {% endfor %}
152153
</div>

0 commit comments

Comments
 (0)