@constructor-io/constructorio-ui-autocomplete
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -59,3 +59,3 @@ "use strict"; | ||
const downshift = (0, useDownShift_1.default)({ setQuery, onChange, items, onSubmit, cioClient, previousQuery }); | ||
const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu } = downshift; | ||
const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex } = downshift; | ||
return { | ||
@@ -89,3 +89,12 @@ query, | ||
(_a = cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker) === null || _a === void 0 ? void 0 : _a.trackInputFocus(); | ||
}, className: 'cio-input', 'data-testid': 'cio-input', placeholder })), | ||
}, className: 'cio-input', 'data-testid': 'cio-input', placeholder, onKeyDownCapture: ({ code }) => { | ||
const isEnter = code === 'Enter'; | ||
const isUserInput = highlightedIndex < 0; | ||
if (isOpen && isEnter && isUserInput && (query === null || query === void 0 ? void 0 : query.length)) { | ||
if (onSubmit) { | ||
onSubmit({ query }); | ||
} | ||
cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackSearchSubmit(query, { original_query: query }); | ||
} | ||
} })), | ||
getFormProps: () => ({ | ||
@@ -92,0 +101,0 @@ onSubmit: (event) => { |
@@ -56,3 +56,3 @@ import { useState } from 'react'; | ||
const downshift = useDownShift({ setQuery, onChange, items, onSubmit, cioClient, previousQuery }); | ||
const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu } = downshift; | ||
const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex } = downshift; | ||
return { | ||
@@ -100,2 +100,12 @@ query, | ||
placeholder, | ||
onKeyDownCapture: ({ code }) => { | ||
const isEnter = code === 'Enter'; | ||
const isUserInput = highlightedIndex < 0; | ||
if (isOpen && isEnter && isUserInput && query?.length) { | ||
if (onSubmit) { | ||
onSubmit({ query }); | ||
} | ||
cioClient?.tracker.trackSearchSubmit(query, { original_query: query }); | ||
} | ||
}, | ||
}), | ||
@@ -102,0 +112,0 @@ getFormProps: () => ({ |
{ | ||
"name": "@constructor-io/constructorio-ui-autocomplete", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Constructor.io Autocomplete UI library for web applications", | ||
@@ -5,0 +5,0 @@ "main": "lib/cjs/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
152687
2025