Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions website/modules/asset/ui/src/searchInputHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,35 @@ const removePreviousHandler = function (input) {
}
};

const getDefaultVisibleCount = function () {
const csContainer = document.querySelector('.cs_container');
let defaultVisibleCount = 5;
if (csContainer) {
const parsed = parseInt(csContainer.dataset.defaultVisibleTags, 10);
if (parsed > 0) {
defaultVisibleCount = parsed;
}
}
return defaultVisibleCount;
};
Comment thread
IhorMasechko marked this conversation as resolved.
Outdated

const toggleShowMoreButtonVisibility = function (
container,
isSearchActive,
totalTags,
defaultVisibleCount,
) {
const showMoreButton = container.querySelector('.tags__show-more');
if (showMoreButton) {
if (isSearchActive) {
showMoreButton.style.display = 'none';
} else {
showMoreButton.style.display =
totalTags > defaultVisibleCount ? 'flex' : 'none';
}
}
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const setupTagSearchForInput = function (input, options) {
const {
containerSelector,
Expand All @@ -85,28 +114,29 @@ const setupTagSearchForInput = function (input, options) {

removePreviousHandler(input);

const csContainer = document.querySelector('.cs_container');
let defaultVisibleCount = 5;
if (csContainer) {
const parsed = parseInt(csContainer.dataset.defaultVisibleTags, 10);
if (parsed > 0) {
defaultVisibleCount = parsed;
}
}
const defaultVisibleCount = getDefaultVisibleCount();

const handler = function () {
const filterValue = input.value.trim().toLowerCase();
const container = input.closest(containerSelector);
if (!container) return;

const tagItems = container.querySelectorAll(tagSelector);
const isSearchActive = filterValue.length > 0;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const hasVisible = filterTags(
tagItems,
filterValue,
getTagLabelFn,
defaultVisibleCount,
);
toggleNoTagsMessage(container, hasVisible);

toggleShowMoreButtonVisibility(
container,
isSearchActive,
tagItems.length,
defaultVisibleCount,
);
};

input.tagSearchHandler = handler;
Expand Down
Loading