ublo-lib 1.47.21 → 1.47.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,7 +15,7 @@ const { publicRuntimeConfig } = getConfig();
|
|
|
15
15
|
const { ubloApi, site } = publicRuntimeConfig;
|
|
16
16
|
const SearchBar = ({ lang, resultFormatter, backdrop, OverrideIcons = {}, messages, seo, exclude, autofocus, additionalResults = [], }) => {
|
|
17
17
|
const input = React.useRef();
|
|
18
|
-
const
|
|
18
|
+
const resultsContainer = React.useRef();
|
|
19
19
|
const [state, setState] = React.useState({ active: 0, selected: undefined });
|
|
20
20
|
const { lang: ubloLang = lang } = useUbloContext();
|
|
21
21
|
const { text, setText, search } = useSearch({
|
|
@@ -55,7 +55,7 @@ const SearchBar = ({ lang, resultFormatter, backdrop, OverrideIcons = {}, messag
|
|
|
55
55
|
close();
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
const container =
|
|
58
|
+
const container = resultsContainer.current;
|
|
59
59
|
const firstResult = container?.querySelector(".search-bar__result");
|
|
60
60
|
const allResults = Array.from(container?.querySelectorAll(".search-bar__result"));
|
|
61
61
|
const lastResult = allResults[allResults.length - 1];
|
|
@@ -121,14 +121,14 @@ const SearchBar = ({ lang, resultFormatter, backdrop, OverrideIcons = {}, messag
|
|
|
121
121
|
const matchingAdditionalResults = additionalResults.filter((result) => {
|
|
122
122
|
const normalizedResult = normalize(result.title.toLowerCase());
|
|
123
123
|
const normalizedText = normalize(text.toLowerCase());
|
|
124
|
-
return normalizedResult.includes(normalizedText);
|
|
124
|
+
return text && normalizedResult.includes(normalizedText);
|
|
125
125
|
});
|
|
126
126
|
const results = [...(search?.result || []), ...matchingAdditionalResults];
|
|
127
127
|
const classes = classNames("search-bar", {
|
|
128
128
|
"search-bar--opened": results.length > 0,
|
|
129
129
|
"search-bar--loading": search?.loading,
|
|
130
130
|
});
|
|
131
|
-
return (_jsxs("div", { className: classes, children: [backdrop && _jsx("div", { className: "search-bar__backdrop", onClick: close }), _jsxs("div", { className: "search-bar__input-container", children: [_jsx("input", { ref: input, type: "text", value: text, onChange: updateSearch, onKeyDown: handleKeyDown, className: "search-bar__input", placeholder: message(ubloLang, "what-are-you-looking-for", messages), onBlur: handleBlur }), _jsx(Icon, { className: "search-bar__icon" }), _jsxs("div", { ref:
|
|
131
|
+
return (_jsxs("div", { className: classes, children: [backdrop && _jsx("div", { className: "search-bar__backdrop", onClick: close }), _jsxs("div", { className: "search-bar__input-container", children: [_jsx("input", { ref: input, type: "text", value: text, onChange: updateSearch, onKeyDown: handleKeyDown, className: "search-bar__input", placeholder: message(ubloLang, "what-are-you-looking-for", messages), onBlur: handleBlur }), _jsx(Icon, { className: "search-bar__icon" }), _jsxs("div", { ref: resultsContainer, className: "search-bar__results", children: [results?.map((result, i) => {
|
|
132
132
|
const { name, title, page, path } = result;
|
|
133
133
|
const externalLink = page === undefined;
|
|
134
134
|
const Tag = externalLink ? "a" : Link;
|
|
@@ -158,7 +158,7 @@ const SearchBar = ({ lang, resultFormatter, backdrop, OverrideIcons = {}, messag
|
|
|
158
158
|
"search-bar__result--active": i === state.active,
|
|
159
159
|
});
|
|
160
160
|
return (_jsx(Tag, { className: classes, ...props, onClick: onClick }, `${name}-${i}`));
|
|
161
|
-
}),
|
|
161
|
+
}), results?.length === 0 && (_jsx("div", { className: "search-bar__no-result", children: message(ubloLang, "no-results", messages) }))] })] })] }));
|
|
162
162
|
};
|
|
163
163
|
export default React.memo(SearchBar);
|
|
164
164
|
function normalize(text) {
|