@canonical/react-components 0.51.3 → 0.51.5
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.
|
@@ -26,7 +26,7 @@ export type Props = PropsWithSpread<{
|
|
|
26
26
|
*/
|
|
27
27
|
onChange?: (inputValue: string) => void;
|
|
28
28
|
/**
|
|
29
|
-
* A function that is called when the user clicks the search icon
|
|
29
|
+
* A function that is called when the user clicks the search icon or presses enter
|
|
30
30
|
*/
|
|
31
31
|
onSearch?: () => void;
|
|
32
32
|
/**
|
|
@@ -42,6 +42,12 @@ const SearchBox = /*#__PURE__*/_react.default.forwardRef((_ref, forwardedRef) =>
|
|
|
42
42
|
const triggerSearch = () => {
|
|
43
43
|
onSearch && onSearch();
|
|
44
44
|
};
|
|
45
|
+
const onKeyDown = e => {
|
|
46
|
+
if (e.key === "Enter" && internalRef.current.checkValidity()) {
|
|
47
|
+
internalRef.current.blur();
|
|
48
|
+
triggerSearch();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
45
51
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
46
52
|
className: (0, _classnames.default)("p-search-box", className)
|
|
47
53
|
}, /*#__PURE__*/_react.default.createElement("label", {
|
|
@@ -54,6 +60,7 @@ const SearchBox = /*#__PURE__*/_react.default.forwardRef((_ref, forwardedRef) =>
|
|
|
54
60
|
id: "search",
|
|
55
61
|
name: "search",
|
|
56
62
|
onChange: evt => onChange === null || onChange === void 0 ? void 0 : onChange(evt.target.value),
|
|
63
|
+
onKeyDown: onKeyDown,
|
|
57
64
|
placeholder: placeholder,
|
|
58
65
|
ref: input => {
|
|
59
66
|
internalRef.current = input;
|