vmui: fix multi-line query (#3448)

* fix: remove prevent nav by up/down keys for multi-line query

* fix: add query params encode in URL
This commit is contained in:
Yury Molodov 2022-12-06 06:56:54 +01:00 committed by Aliaksandr Valialkin
parent ff1c654006
commit 8f501ca220
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 4 additions and 3 deletions

View file

@ -56,13 +56,14 @@ const Autocomplete: FC<AutocompleteProps> = ({
const handleKeyDown = (e: KeyboardEvent) => { const handleKeyDown = (e: KeyboardEvent) => {
const { key, ctrlKey, metaKey, shiftKey } = e; const { key, ctrlKey, metaKey, shiftKey } = e;
const modifiers = ctrlKey || metaKey || shiftKey; const modifiers = ctrlKey || metaKey || shiftKey;
const hasOptions = foundOptions.length;
if (key === "ArrowUp" && !modifiers) { if (key === "ArrowUp" && !modifiers && hasOptions) {
e.preventDefault(); e.preventDefault();
setFocusOption((prev) => prev <= 0 ? 0 : prev - 1); setFocusOption((prev) => prev <= 0 ? 0 : prev - 1);
} }
if (key === "ArrowDown" && !modifiers) { if (key === "ArrowDown" && !modifiers && hasOptions) {
e.preventDefault(); e.preventDefault();
const lastIndex = foundOptions.length - 1; const lastIndex = foundOptions.length - 1;
setFocusOption((prev) => prev >= lastIndex ? lastIndex : prev + 1); setFocusOption((prev) => prev >= lastIndex ? lastIndex : prev + 1);

View file

@ -5,7 +5,7 @@ import { MAX_QUERY_FIELDS } from "../constants/graph";
export const setQueryStringWithoutPageReload = (params: Record<string, unknown>): void => { export const setQueryStringWithoutPageReload = (params: Record<string, unknown>): void => {
const w = window; const w = window;
if (w) { if (w) {
const qsValue = Object.entries(params).map(([k, v]) => `${k}=${v}`).join("&"); const qsValue = Object.entries(params).map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`).join("&");
const qs = qsValue ? `?${qsValue}` : ""; const qs = qsValue ? `?${qsValue}` : "";
const newurl = `${w.location.protocol}//${w.location.host}${w.location.pathname}${qs}${w.location.hash}`; const newurl = `${w.location.protocol}//${w.location.host}${w.location.pathname}${qs}${w.location.hash}`;
w.history.pushState({ path: newurl }, "", newurl); w.history.pushState({ path: newurl }, "", newurl);