@homebound/beam 2.97.3 → 2.97.4
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.
|
@@ -8,8 +8,12 @@ const utils_1 = require("../utils");
|
|
|
8
8
|
const defaultLabel_1 = require("../utils/defaultLabel");
|
|
9
9
|
/** Wraps `TextField` and binds it to a form field. */
|
|
10
10
|
function BoundTextField(props) {
|
|
11
|
-
const { field, readOnly, onChange = (value) => field.set(value), label = (0, defaultLabel_1.defaultLabel)(field.key), ...others } = props;
|
|
11
|
+
const { field, readOnly, onChange = (value) => field.set(value), label = (0, defaultLabel_1.defaultLabel)(field.key), onEnter, ...others } = props;
|
|
12
12
|
const testId = (0, utils_1.useTestIds)(props, field.key);
|
|
13
|
-
return ((0, jsx_runtime_1.jsx)(mobx_react_1.Observer, { children: () => ((0, jsx_runtime_1.jsx)(inputs_1.TextField, Object.assign({ label: label, value: field.value || undefined, onChange: onChange, readOnly: readOnly !== null && readOnly !== void 0 ? readOnly : field.readOnly, errorMsg: field.touched ? field.errors.join(" ") : undefined, required: field.required, onBlur: () => field.blur(), onFocus: () => field.focus()
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(mobx_react_1.Observer, { children: () => ((0, jsx_runtime_1.jsx)(inputs_1.TextField, Object.assign({ label: label, value: field.value || undefined, onChange: onChange, readOnly: readOnly !== null && readOnly !== void 0 ? readOnly : field.readOnly, errorMsg: field.touched ? field.errors.join(" ") : undefined, required: field.required, onBlur: () => field.blur(), onFocus: () => field.focus(), onEnter: () => {
|
|
14
|
+
(0, utils_1.maybeCall)(onEnter);
|
|
15
|
+
// Blur the field when the user hits the enter key - as if they are "committing" the value and done with the field
|
|
16
|
+
field.blur();
|
|
17
|
+
} }, testId, others), void 0)) }, void 0));
|
|
14
18
|
}
|
|
15
19
|
exports.BoundTextField = BoundTextField;
|
|
@@ -7,6 +7,7 @@ export interface TextFieldProps<X> extends BeamTextFieldProps<X> {
|
|
|
7
7
|
inlineLabel?: boolean;
|
|
8
8
|
clearable?: boolean;
|
|
9
9
|
api?: MutableRefObject<TextFieldApi | undefined>;
|
|
10
|
+
onEnter?: Callback;
|
|
10
11
|
}
|
|
11
12
|
export declare function TextField<X extends Only<TextFieldXss, X>>(props: TextFieldProps<X>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
12
13
|
export declare type TextFieldApi = {
|
package/dist/inputs/TextField.js
CHANGED
|
@@ -5,8 +5,9 @@ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const react_aria_1 = require("react-aria");
|
|
7
7
|
const TextFieldBase_1 = require("./TextFieldBase");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
8
9
|
function TextField(props) {
|
|
9
|
-
const { disabled: isDisabled = false, readOnly = false, required, errorMsg, value = "", onBlur, onFocus, api, ...otherProps } = props;
|
|
10
|
+
const { disabled: isDisabled = false, readOnly = false, required, errorMsg, value = "", onBlur, onFocus, api, onEnter, ...otherProps } = props;
|
|
10
11
|
const textFieldProps = {
|
|
11
12
|
...otherProps,
|
|
12
13
|
isDisabled,
|
|
@@ -19,10 +20,8 @@ function TextField(props) {
|
|
|
19
20
|
const { labelProps, inputProps } = (0, react_aria_1.useTextField)({
|
|
20
21
|
...textFieldProps,
|
|
21
22
|
onKeyDown: (e) => {
|
|
22
|
-
var _a;
|
|
23
23
|
if (e.key === "Enter") {
|
|
24
|
-
|
|
25
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
24
|
+
(0, utils_1.maybeCall)(onEnter);
|
|
26
25
|
}
|
|
27
26
|
},
|
|
28
27
|
}, inputRef);
|