@react-aria/textfield 3.14.3 → 3.14.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.
@@ -0,0 +1,131 @@
1
+ import {useTextField as $2d73ec29415bd339$export$712718f7aec83d5} from "./useTextField.module.js";
2
+ import {useEffectEvent as $jyGKS$useEffectEvent, mergeProps as $jyGKS$mergeProps} from "@react-aria/utils";
3
+ import {useEffect as $jyGKS$useEffect, useRef as $jyGKS$useRef} from "react";
4
+
5
+ /*
6
+ * Copyright 2021 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $d841c8010a73d545$var$supportsNativeBeforeInputEvent() {
19
+ return typeof window !== "undefined" && window.InputEvent && // @ts-ignore
20
+ typeof InputEvent.prototype.getTargetRanges === "function";
21
+ }
22
+ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
23
+ // All browsers implement the 'beforeinput' event natively except Firefox
24
+ // (currently behind a flag as of Firefox 84). React's polyfill does not
25
+ // run in all cases that the native event fires, e.g. when deleting text.
26
+ // Use the native event if available so that we can prevent invalid deletions.
27
+ // We do not attempt to polyfill this in Firefox since it would be very complicated,
28
+ // the benefit of doing so is fairly minor, and it's going to be natively supported soon.
29
+ let onBeforeInputFallback = (0, $jyGKS$useEffectEvent)((e)=>{
30
+ let input = inputRef.current;
31
+ // Compute the next value of the input if the event is allowed to proceed.
32
+ // See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
33
+ let nextValue;
34
+ switch(e.inputType){
35
+ case "historyUndo":
36
+ case "historyRedo":
37
+ // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,
38
+ // because presumably the input would have already been validated previously.
39
+ return;
40
+ case "insertLineBreak":
41
+ // Explicitly allow "insertLineBreak" event, to allow onSubmit for "enter" key. e.data is null in this case.
42
+ return;
43
+ case "deleteContent":
44
+ case "deleteByCut":
45
+ case "deleteByDrag":
46
+ nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
47
+ break;
48
+ case "deleteContentForward":
49
+ // This is potentially incorrect, since the browser may actually delete more than a single UTF-16
50
+ // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters
51
+ // or code points may be deleted. However, in our currently supported locales, there are no such cases.
52
+ // If we support additional locales in the future, this may need to change.
53
+ nextValue = input.selectionEnd === input.selectionStart ? input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd + 1) : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
54
+ break;
55
+ case "deleteContentBackward":
56
+ nextValue = input.selectionEnd === input.selectionStart ? input.value.slice(0, input.selectionStart - 1) + input.value.slice(input.selectionStart) : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
57
+ break;
58
+ case "deleteSoftLineBackward":
59
+ case "deleteHardLineBackward":
60
+ nextValue = input.value.slice(input.selectionStart);
61
+ break;
62
+ default:
63
+ if (e.data != null) nextValue = input.value.slice(0, input.selectionStart) + e.data + input.value.slice(input.selectionEnd);
64
+ break;
65
+ }
66
+ // If we did not compute a value, or the new value is invalid, prevent the event
67
+ // so that the browser does not update the input text, move the selection, or add to
68
+ // the undo/redo stack.
69
+ if (nextValue == null || !state.validate(nextValue)) e.preventDefault();
70
+ });
71
+ (0, $jyGKS$useEffect)(()=>{
72
+ if (!$d841c8010a73d545$var$supportsNativeBeforeInputEvent()) return;
73
+ let input = inputRef.current;
74
+ input.addEventListener("beforeinput", onBeforeInputFallback, false);
75
+ return ()=>{
76
+ input.removeEventListener("beforeinput", onBeforeInputFallback, false);
77
+ };
78
+ }, [
79
+ inputRef,
80
+ onBeforeInputFallback
81
+ ]);
82
+ let onBeforeInput = !$d841c8010a73d545$var$supportsNativeBeforeInputEvent() ? (e)=>{
83
+ let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
84
+ if (!state.validate(nextValue)) e.preventDefault();
85
+ } : null;
86
+ let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps, ...validation } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
87
+ let compositionStartState = (0, $jyGKS$useRef)(null);
88
+ return {
89
+ inputProps: (0, $jyGKS$mergeProps)(textFieldProps, {
90
+ onBeforeInput: onBeforeInput,
91
+ onCompositionStart () {
92
+ // Chrome does not implement Input Events Level 2, which specifies the insertFromComposition
93
+ // and deleteByComposition inputType values for the beforeinput event. These are meant to occur
94
+ // at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are
95
+ // cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,
96
+ // nor would we want to cancel them because the input from the user is incomplete at that point.
97
+ // In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel
98
+ // the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either
99
+ // don't support Input Events Level 2, or beforeinput at all, we store the state of the input when
100
+ // the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.
101
+ // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
102
+ // are implemented, there is no other way to prevent composed input.
103
+ // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
104
+ let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = inputRef.current;
105
+ compositionStartState.current = {
106
+ value: value,
107
+ selectionStart: selectionStart,
108
+ selectionEnd: selectionEnd
109
+ };
110
+ },
111
+ onCompositionEnd () {
112
+ if (!state.validate(inputRef.current.value)) {
113
+ // Restore the input value in the DOM immediately so we can synchronously update the selection position.
114
+ // But also update the value in React state as well so it is correct for future updates.
115
+ let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = compositionStartState.current;
116
+ inputRef.current.value = value;
117
+ inputRef.current.setSelectionRange(selectionStart, selectionEnd);
118
+ state.setInputValue(value);
119
+ }
120
+ }
121
+ }),
122
+ labelProps: labelProps,
123
+ descriptionProps: descriptionProps,
124
+ errorMessageProps: errorMessageProps,
125
+ ...validation
126
+ };
127
+ }
128
+
129
+
130
+ export {$d841c8010a73d545$export$4f384c9210e583c3 as useFormattedTextField};
131
+ //# sourceMappingURL=useFormattedTextField.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"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","sources":["packages/@react-aria/textfield/src/useFormattedTextField.ts"],"sourcesContent":["/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {TextFieldAria, useTextField} from './useTextField';\n\ninterface FormattedTextFieldState {\n validate: (val: string) => boolean,\n setInputValue: (val: string) => void\n}\n\n\nfunction supportsNativeBeforeInputEvent() {\n return typeof window !== 'undefined' &&\n window.InputEvent &&\n // @ts-ignore\n typeof InputEvent.prototype.getTargetRanges === 'function';\n}\n\nexport function useFormattedTextField(props: AriaTextFieldProps, state: FormattedTextFieldState, inputRef: RefObject<HTMLInputElement>): TextFieldAria {\n // All browsers implement the 'beforeinput' event natively except Firefox\n // (currently behind a flag as of Firefox 84). React's polyfill does not\n // run in all cases that the native event fires, e.g. when deleting text.\n // Use the native event if available so that we can prevent invalid deletions.\n // We do not attempt to polyfill this in Firefox since it would be very complicated,\n // the benefit of doing so is fairly minor, and it's going to be natively supported soon.\n let onBeforeInputFallback = useEffectEvent((e: InputEvent) => {\n let input = inputRef.current;\n\n // Compute the next value of the input if the event is allowed to proceed.\n // See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.\n let nextValue: string;\n switch (e.inputType) {\n case 'historyUndo':\n case 'historyRedo':\n // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,\n // because presumably the input would have already been validated previously.\n return;\n case 'insertLineBreak':\n // Explicitly allow \"insertLineBreak\" event, to allow onSubmit for \"enter\" key. e.data is null in this case.\n return;\n case 'deleteContent':\n case 'deleteByCut':\n case 'deleteByDrag':\n nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n break;\n case 'deleteContentForward':\n // This is potentially incorrect, since the browser may actually delete more than a single UTF-16\n // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters\n // or code points may be deleted. However, in our currently supported locales, there are no such cases.\n // If we support additional locales in the future, this may need to change.\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd + 1)\n : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n break;\n case 'deleteContentBackward':\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart - 1) + input.value.slice(input.selectionStart)\n : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n break;\n case 'deleteSoftLineBackward':\n case 'deleteHardLineBackward':\n nextValue = input.value.slice(input.selectionStart);\n break;\n default:\n if (e.data != null) {\n nextValue =\n input.value.slice(0, input.selectionStart) +\n e.data +\n input.value.slice(input.selectionEnd);\n }\n break;\n }\n\n // If we did not compute a value, or the new value is invalid, prevent the event\n // so that the browser does not update the input text, move the selection, or add to\n // the undo/redo stack.\n if (nextValue == null || !state.validate(nextValue)) {\n e.preventDefault();\n }\n });\n\n useEffect(() => {\n if (!supportsNativeBeforeInputEvent()) {\n return;\n }\n\n let input = inputRef.current;\n input.addEventListener('beforeinput', onBeforeInputFallback, false);\n return () => {\n input.removeEventListener('beforeinput', onBeforeInputFallback, false);\n };\n }, [inputRef, onBeforeInputFallback]);\n\n let onBeforeInput = !supportsNativeBeforeInputEvent()\n ? e => {\n let nextValue =\n e.target.value.slice(0, e.target.selectionStart) +\n e.data +\n e.target.value.slice(e.target.selectionEnd);\n\n if (!state.validate(nextValue)) {\n e.preventDefault();\n }\n }\n : null;\n\n let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps, ...validation} = useTextField(props, inputRef);\n\n let compositionStartState = useRef(null);\n return {\n inputProps: mergeProps(\n textFieldProps,\n {\n onBeforeInput,\n onCompositionStart() {\n // Chrome does not implement Input Events Level 2, which specifies the insertFromComposition\n // and deleteByComposition inputType values for the beforeinput event. These are meant to occur\n // at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are\n // cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,\n // nor would we want to cancel them because the input from the user is incomplete at that point.\n // In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel\n // the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either\n // don't support Input Events Level 2, or beforeinput at all, we store the state of the input when\n // the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.\n // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition\n // are implemented, there is no other way to prevent composed input.\n // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204\n let {value, selectionStart, selectionEnd} = inputRef.current;\n compositionStartState.current = {value, selectionStart, selectionEnd};\n },\n onCompositionEnd() {\n if (!state.validate(inputRef.current.value)) {\n // Restore the input value in the DOM immediately so we can synchronously update the selection position.\n // But also update the value in React state as well so it is correct for future updates.\n let {value, selectionStart, selectionEnd} = compositionStartState.current;\n inputRef.current.value = value;\n inputRef.current.setSelectionRange(selectionStart, selectionEnd);\n state.setInputValue(value);\n }\n }\n }\n ),\n labelProps,\n descriptionProps,\n errorMessageProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useFormattedTextField.module.js.map"}
@@ -0,0 +1,120 @@
1
+ var $4Z7CR$react = require("react");
2
+ var $4Z7CR$reactariautils = require("@react-aria/utils");
3
+ var $4Z7CR$reactstatelyutils = require("@react-stately/utils");
4
+ var $4Z7CR$reactarialabel = require("@react-aria/label");
5
+ var $4Z7CR$reactariafocus = require("@react-aria/focus");
6
+ var $4Z7CR$reactariaform = require("@react-aria/form");
7
+ var $4Z7CR$reactstatelyform = require("@react-stately/form");
8
+
9
+
10
+ function $parcel$export(e, n, v, s) {
11
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
12
+ }
13
+
14
+ $parcel$export(module.exports, "useTextField", () => $9076f978e02df845$export$712718f7aec83d5);
15
+ /*
16
+ * Copyright 2020 Adobe. All rights reserved.
17
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
18
+ * you may not use this file except in compliance with the License. You may obtain a copy
19
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software distributed under
22
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
23
+ * OF ANY KIND, either express or implied. See the License for the specific language
24
+ * governing permissions and limitations under the License.
25
+ */
26
+
27
+
28
+
29
+
30
+
31
+
32
+ function $9076f978e02df845$export$712718f7aec83d5(props, ref) {
33
+ let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, type: type = "text", validationBehavior: validationBehavior = "aria" } = props;
34
+ let [value, setValue] = (0, $4Z7CR$reactstatelyutils.useControlledState)(props.value, props.defaultValue || "", props.onChange);
35
+ let { focusableProps: focusableProps } = (0, $4Z7CR$reactariafocus.useFocusable)(props, ref);
36
+ let validationState = (0, $4Z7CR$reactstatelyform.useFormValidationState)({
37
+ ...props,
38
+ value: value
39
+ });
40
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
41
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $4Z7CR$reactarialabel.useField)({
42
+ ...props,
43
+ isInvalid: isInvalid,
44
+ errorMessage: props.errorMessage || validationErrors
45
+ });
46
+ let domProps = (0, $4Z7CR$reactariautils.filterDOMProps)(props, {
47
+ labelable: true
48
+ });
49
+ const inputOnlyProps = {
50
+ type: type,
51
+ pattern: props.pattern
52
+ };
53
+ (0, $4Z7CR$reactariautils.useFormReset)(ref, value, setValue);
54
+ (0, $4Z7CR$reactariaform.useFormValidation)(props, validationState, ref);
55
+ (0, $4Z7CR$react.useEffect)(()=>{
56
+ // This works around a React/Chrome bug that prevents textarea elements from validating when controlled.
57
+ // We prevent React from updating defaultValue (i.e. children) of textarea when `value` changes,
58
+ // which causes Chrome to skip validation. Only updating `value` is ok in our case since our
59
+ // textareas are always controlled. React is planning on removing this synchronization in a
60
+ // future major version.
61
+ // https://github.com/facebook/react/issues/19474
62
+ // https://github.com/facebook/react/issues/11896
63
+ if (ref.current instanceof (0, $4Z7CR$reactariautils.getOwnerWindow)(ref.current).HTMLTextAreaElement) {
64
+ let input = ref.current;
65
+ Object.defineProperty(input, "defaultValue", {
66
+ get: ()=>input.value,
67
+ set: ()=>{},
68
+ configurable: true
69
+ });
70
+ }
71
+ }, [
72
+ ref
73
+ ]);
74
+ return {
75
+ labelProps: labelProps,
76
+ inputProps: (0, $4Z7CR$reactariautils.mergeProps)(domProps, inputElementType === "input" && inputOnlyProps, {
77
+ disabled: isDisabled,
78
+ readOnly: isReadOnly,
79
+ required: isRequired && validationBehavior === "native",
80
+ "aria-required": isRequired && validationBehavior === "aria" || undefined,
81
+ "aria-invalid": isInvalid || undefined,
82
+ "aria-errormessage": props["aria-errormessage"],
83
+ "aria-activedescendant": props["aria-activedescendant"],
84
+ "aria-autocomplete": props["aria-autocomplete"],
85
+ "aria-haspopup": props["aria-haspopup"],
86
+ value: value,
87
+ onChange: (e)=>setValue(e.target.value),
88
+ autoComplete: props.autoComplete,
89
+ autoCapitalize: props.autoCapitalize,
90
+ maxLength: props.maxLength,
91
+ minLength: props.minLength,
92
+ name: props.name,
93
+ placeholder: props.placeholder,
94
+ inputMode: props.inputMode,
95
+ // Clipboard events
96
+ onCopy: props.onCopy,
97
+ onCut: props.onCut,
98
+ onPaste: props.onPaste,
99
+ // Composition events
100
+ onCompositionEnd: props.onCompositionEnd,
101
+ onCompositionStart: props.onCompositionStart,
102
+ onCompositionUpdate: props.onCompositionUpdate,
103
+ // Selection events
104
+ onSelect: props.onSelect,
105
+ // Input events
106
+ onBeforeInput: props.onBeforeInput,
107
+ onInput: props.onInput,
108
+ ...focusableProps,
109
+ ...fieldProps
110
+ }),
111
+ descriptionProps: descriptionProps,
112
+ errorMessageProps: errorMessageProps,
113
+ isInvalid: isInvalid,
114
+ validationErrors: validationErrors,
115
+ validationDetails: validationDetails
116
+ };
117
+ }
118
+
119
+
120
+ //# sourceMappingURL=useTextField.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAsGM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,aACb,OAAO,4BACP,qBAAqB,QACtB,GAAqD;IACtD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,2CAAiB,EAAU,MAAM,KAAK,EAAE,MAAM,YAAY,IAAI,IAAI,MAAM,QAAQ;IACxG,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,OAAO;IAC3C,IAAI,kBAAkB,CAAA,GAAA,8CAAqB,EAAE;QAC3C,GAAG,KAAK;eACR;IACF;IACA,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,gBAAgB,iBAAiB;IACxF,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;QAC3E,GAAG,KAAK;mBACR;QACA,cAAc,MAAM,YAAY,IAAI;IACtC;IACA,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,MAAM,iBAAiB;cACrB;QACA,SAAS,MAAM,OAAO;IACxB;IAEA,CAAA,GAAA,kCAAW,EAAE,KAAK,OAAO;IACzB,CAAA,GAAA,sCAAgB,EAAE,OAAO,iBAAiB;IAE1C,CAAA,GAAA,sBAAQ,EAAE;QACR,wGAAwG;QACxG,gGAAgG;QAChG,4FAA4F;QAC5F,2FAA2F;QAC3F,wBAAwB;QACxB,iDAAiD;QACjD,iDAAiD;QACjD,IAAI,IAAI,OAAO,YAAY,CAAA,GAAA,oCAAa,EAAE,IAAI,OAAO,EAAE,mBAAmB,EAAE;YAC1E,IAAI,QAAQ,IAAI,OAAO;YACvB,OAAO,cAAc,CAAC,OAAO,gBAAgB;gBAC3C,KAAK,IAAM,MAAM,KAAK;gBACtB,KAAK,KAAO;gBACZ,cAAc;YAChB;QACF;IACF,GAAG;QAAC;KAAI;IAER,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,gCAAS,EACnB,UACA,qBAAqB,WAAW,gBAChC;YACE,UAAU;YACV,UAAU;YACV,UAAU,cAAc,uBAAuB;YAC/C,iBAAiB,AAAC,cAAc,uBAAuB,UAAW;YAClE,gBAAgB,aAAa;YAC7B,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,yBAAyB,KAAK,CAAC,wBAAwB;YACvD,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;mBACvC;YACA,UAAU,CAAC,IAAqC,SAAS,EAAE,MAAM,CAAC,KAAK;YACvE,cAAc,MAAM,YAAY;YAChC,gBAAgB,MAAM,cAAc;YACpC,WAAW,MAAM,SAAS;YAC1B,WAAW,MAAM,SAAS;YAC1B,MAAM,MAAM,IAAI;YAChB,aAAa,MAAM,WAAW;YAC9B,WAAW,MAAM,SAAS;YAE1B,mBAAmB;YACnB,QAAQ,MAAM,MAAM;YACpB,OAAO,MAAM,KAAK;YAClB,SAAS,MAAM,OAAO;YAEtB,qBAAqB;YACrB,kBAAkB,MAAM,gBAAgB;YACxC,oBAAoB,MAAM,kBAAkB;YAC5C,qBAAqB,MAAM,mBAAmB;YAE9C,mBAAmB;YACnB,UAAU,MAAM,QAAQ;YAExB,eAAe;YACf,eAAe,MAAM,aAAa;YAClC,SAAS,MAAM,OAAO;YACtB,GAAG,cAAc;YACjB,GAAG,UAAU;QACf;0BAEF;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/textfield/src/useTextField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {\n ChangeEvent,\n DOMFactory,\n HTMLAttributes,\n LabelHTMLAttributes,\n ReactDOM,\n RefObject,\n useEffect\n} from 'react';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, getOwnerWindow, mergeProps, useFormReset} from '@react-aria/utils';\nimport {useControlledState} from '@react-stately/utils';\nimport {useField} from '@react-aria/label';\nimport {useFocusable} from '@react-aria/focus';\nimport {useFormValidation} from '@react-aria/form';\nimport {useFormValidationState} from '@react-stately/form';\n\n/**\n * A map of HTML element names and their interface types.\n * For example `'a'` -> `HTMLAnchorElement`.\n */\ntype IntrinsicHTMLElements = {\n [K in keyof IntrinsicHTMLAttributes]: IntrinsicHTMLAttributes[K] extends HTMLAttributes<infer T> ? T : never\n};\n\n/**\n * A map of HTML element names and their attribute interface types.\n * For example `'a'` -> `AnchorHTMLAttributes<HTMLAnchorElement>`.\n */\ntype IntrinsicHTMLAttributes = {\n [K in keyof ReactDOM]: ReactDOM[K] extends DOMFactory<infer T, any> ? T : never\n};\n\ntype DefaultElementType = 'input';\n\n/**\n * The intrinsic HTML element names that `useTextField` supports; e.g. `input`,\n * `textarea`.\n */\ntype TextFieldIntrinsicElements = keyof Pick<IntrinsicHTMLElements, 'input' | 'textarea'>;\n\n/**\n * The HTML element interfaces that `useTextField` supports based on what is\n * defined for `TextFieldIntrinsicElements`; e.g. `HTMLInputElement`,\n * `HTMLTextAreaElement`.\n */\ntype TextFieldHTMLElementType = Pick<IntrinsicHTMLElements, TextFieldIntrinsicElements>;\n\n/**\n * The HTML attributes interfaces that `useTextField` supports based on what\n * is defined for `TextFieldIntrinsicElements`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldHTMLAttributesType = Pick<IntrinsicHTMLAttributes, TextFieldIntrinsicElements>;\n\n/**\n * The type of `inputProps` returned by `useTextField`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldInputProps<T extends TextFieldIntrinsicElements> = TextFieldHTMLAttributesType[T];\n\nexport interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps {\n /**\n * The HTML element used to render the input, e.g. 'input', or 'textarea'.\n * It determines whether certain HTML attributes will be included in `inputProps`.\n * For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).\n * @default 'input'\n */\n inputElementType?: T,\n /**\n * Controls whether inputted text is automatically capitalized and, if so, in what manner. \n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize).\n */\n autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'\n}\n\n/**\n * The type of `ref` object that can be passed to `useTextField` based on the given\n * intrinsic HTML element name; e.g.`RefObject<HTMLInputElement>`,\n * `RefObject<HTMLTextAreaElement>`.\n */\ntype TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T]>;\n\nexport interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> extends ValidationResult {\n /** Props for the input element. */\n inputProps: TextFieldInputProps<T>,\n /** Props for the text field's visible label element, if any. */\n labelProps: DOMAttributes | LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the text field's description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the text field's error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a text field.\n * @param props - Props for the text field.\n * @param ref - Ref to the HTML input or textarea element.\n */\nexport function useTextField<T extends TextFieldIntrinsicElements = DefaultElementType>(\n props: AriaTextFieldOptions<T>,\n ref: TextFieldRefObject<T>\n): TextFieldAria<T> {\n let {\n inputElementType = 'input',\n isDisabled = false,\n isRequired = false,\n isReadOnly = false,\n type = 'text',\n validationBehavior = 'aria'\n }: AriaTextFieldOptions<TextFieldIntrinsicElements> = props;\n let [value, setValue] = useControlledState<string>(props.value, props.defaultValue || '', props.onChange);\n let {focusableProps} = useFocusable(props, ref);\n let validationState = useFormValidationState({\n ...props,\n value\n });\n let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n let domProps = filterDOMProps(props, {labelable: true});\n\n const inputOnlyProps = {\n type,\n pattern: props.pattern\n };\n\n useFormReset(ref, value, setValue);\n useFormValidation(props, validationState, ref);\n\n useEffect(() => {\n // This works around a React/Chrome bug that prevents textarea elements from validating when controlled.\n // We prevent React from updating defaultValue (i.e. children) of textarea when `value` changes,\n // which causes Chrome to skip validation. Only updating `value` is ok in our case since our\n // textareas are always controlled. React is planning on removing this synchronization in a\n // future major version.\n // https://github.com/facebook/react/issues/19474\n // https://github.com/facebook/react/issues/11896\n if (ref.current instanceof getOwnerWindow(ref.current).HTMLTextAreaElement) {\n let input = ref.current;\n Object.defineProperty(input, 'defaultValue', {\n get: () => input.value,\n set: () => {},\n configurable: true\n });\n }\n }, [ref]);\n\n return {\n labelProps,\n inputProps: mergeProps(\n domProps,\n inputElementType === 'input' && inputOnlyProps,\n {\n disabled: isDisabled,\n readOnly: isReadOnly,\n required: isRequired && validationBehavior === 'native',\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n 'aria-invalid': isInvalid || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-activedescendant': props['aria-activedescendant'],\n 'aria-autocomplete': props['aria-autocomplete'],\n 'aria-haspopup': props['aria-haspopup'],\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),\n autoComplete: props.autoComplete,\n autoCapitalize: props.autoCapitalize,\n maxLength: props.maxLength,\n minLength: props.minLength,\n name: props.name,\n placeholder: props.placeholder,\n inputMode: props.inputMode,\n\n // Clipboard events\n onCopy: props.onCopy,\n onCut: props.onCut,\n onPaste: props.onPaste,\n\n // Composition events\n onCompositionEnd: props.onCompositionEnd,\n onCompositionStart: props.onCompositionStart,\n onCompositionUpdate: props.onCompositionUpdate,\n\n // Selection events\n onSelect: props.onSelect,\n\n // Input events\n onBeforeInput: props.onBeforeInput,\n onInput: props.onInput,\n ...focusableProps,\n ...fieldProps\n }\n ),\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useTextField.main.js.map"}
@@ -0,0 +1,115 @@
1
+ import {useEffect as $ig234$useEffect} from "react";
2
+ import {filterDOMProps as $ig234$filterDOMProps, useFormReset as $ig234$useFormReset, getOwnerWindow as $ig234$getOwnerWindow, mergeProps as $ig234$mergeProps} from "@react-aria/utils";
3
+ import {useControlledState as $ig234$useControlledState} from "@react-stately/utils";
4
+ import {useField as $ig234$useField} from "@react-aria/label";
5
+ import {useFocusable as $ig234$useFocusable} from "@react-aria/focus";
6
+ import {useFormValidation as $ig234$useFormValidation} from "@react-aria/form";
7
+ import {useFormValidationState as $ig234$useFormValidationState} from "@react-stately/form";
8
+
9
+ /*
10
+ * Copyright 2020 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+
21
+
22
+
23
+
24
+
25
+
26
+ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
27
+ let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, type: type = "text", validationBehavior: validationBehavior = "aria" } = props;
28
+ let [value, setValue] = (0, $ig234$useControlledState)(props.value, props.defaultValue || "", props.onChange);
29
+ let { focusableProps: focusableProps } = (0, $ig234$useFocusable)(props, ref);
30
+ let validationState = (0, $ig234$useFormValidationState)({
31
+ ...props,
32
+ value: value
33
+ });
34
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
35
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $ig234$useField)({
36
+ ...props,
37
+ isInvalid: isInvalid,
38
+ errorMessage: props.errorMessage || validationErrors
39
+ });
40
+ let domProps = (0, $ig234$filterDOMProps)(props, {
41
+ labelable: true
42
+ });
43
+ const inputOnlyProps = {
44
+ type: type,
45
+ pattern: props.pattern
46
+ };
47
+ (0, $ig234$useFormReset)(ref, value, setValue);
48
+ (0, $ig234$useFormValidation)(props, validationState, ref);
49
+ (0, $ig234$useEffect)(()=>{
50
+ // This works around a React/Chrome bug that prevents textarea elements from validating when controlled.
51
+ // We prevent React from updating defaultValue (i.e. children) of textarea when `value` changes,
52
+ // which causes Chrome to skip validation. Only updating `value` is ok in our case since our
53
+ // textareas are always controlled. React is planning on removing this synchronization in a
54
+ // future major version.
55
+ // https://github.com/facebook/react/issues/19474
56
+ // https://github.com/facebook/react/issues/11896
57
+ if (ref.current instanceof (0, $ig234$getOwnerWindow)(ref.current).HTMLTextAreaElement) {
58
+ let input = ref.current;
59
+ Object.defineProperty(input, "defaultValue", {
60
+ get: ()=>input.value,
61
+ set: ()=>{},
62
+ configurable: true
63
+ });
64
+ }
65
+ }, [
66
+ ref
67
+ ]);
68
+ return {
69
+ labelProps: labelProps,
70
+ inputProps: (0, $ig234$mergeProps)(domProps, inputElementType === "input" && inputOnlyProps, {
71
+ disabled: isDisabled,
72
+ readOnly: isReadOnly,
73
+ required: isRequired && validationBehavior === "native",
74
+ "aria-required": isRequired && validationBehavior === "aria" || undefined,
75
+ "aria-invalid": isInvalid || undefined,
76
+ "aria-errormessage": props["aria-errormessage"],
77
+ "aria-activedescendant": props["aria-activedescendant"],
78
+ "aria-autocomplete": props["aria-autocomplete"],
79
+ "aria-haspopup": props["aria-haspopup"],
80
+ value: value,
81
+ onChange: (e)=>setValue(e.target.value),
82
+ autoComplete: props.autoComplete,
83
+ autoCapitalize: props.autoCapitalize,
84
+ maxLength: props.maxLength,
85
+ minLength: props.minLength,
86
+ name: props.name,
87
+ placeholder: props.placeholder,
88
+ inputMode: props.inputMode,
89
+ // Clipboard events
90
+ onCopy: props.onCopy,
91
+ onCut: props.onCut,
92
+ onPaste: props.onPaste,
93
+ // Composition events
94
+ onCompositionEnd: props.onCompositionEnd,
95
+ onCompositionStart: props.onCompositionStart,
96
+ onCompositionUpdate: props.onCompositionUpdate,
97
+ // Selection events
98
+ onSelect: props.onSelect,
99
+ // Input events
100
+ onBeforeInput: props.onBeforeInput,
101
+ onInput: props.onInput,
102
+ ...focusableProps,
103
+ ...fieldProps
104
+ }),
105
+ descriptionProps: descriptionProps,
106
+ errorMessageProps: errorMessageProps,
107
+ isInvalid: isInvalid,
108
+ validationErrors: validationErrors,
109
+ validationDetails: validationDetails
110
+ };
111
+ }
112
+
113
+
114
+ export {$2d73ec29415bd339$export$712718f7aec83d5 as useTextField};
115
+ //# sourceMappingURL=useTextField.mjs.map
@@ -0,0 +1,115 @@
1
+ import {useEffect as $ig234$useEffect} from "react";
2
+ import {filterDOMProps as $ig234$filterDOMProps, useFormReset as $ig234$useFormReset, getOwnerWindow as $ig234$getOwnerWindow, mergeProps as $ig234$mergeProps} from "@react-aria/utils";
3
+ import {useControlledState as $ig234$useControlledState} from "@react-stately/utils";
4
+ import {useField as $ig234$useField} from "@react-aria/label";
5
+ import {useFocusable as $ig234$useFocusable} from "@react-aria/focus";
6
+ import {useFormValidation as $ig234$useFormValidation} from "@react-aria/form";
7
+ import {useFormValidationState as $ig234$useFormValidationState} from "@react-stately/form";
8
+
9
+ /*
10
+ * Copyright 2020 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+
21
+
22
+
23
+
24
+
25
+
26
+ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
27
+ let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, type: type = "text", validationBehavior: validationBehavior = "aria" } = props;
28
+ let [value, setValue] = (0, $ig234$useControlledState)(props.value, props.defaultValue || "", props.onChange);
29
+ let { focusableProps: focusableProps } = (0, $ig234$useFocusable)(props, ref);
30
+ let validationState = (0, $ig234$useFormValidationState)({
31
+ ...props,
32
+ value: value
33
+ });
34
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
35
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $ig234$useField)({
36
+ ...props,
37
+ isInvalid: isInvalid,
38
+ errorMessage: props.errorMessage || validationErrors
39
+ });
40
+ let domProps = (0, $ig234$filterDOMProps)(props, {
41
+ labelable: true
42
+ });
43
+ const inputOnlyProps = {
44
+ type: type,
45
+ pattern: props.pattern
46
+ };
47
+ (0, $ig234$useFormReset)(ref, value, setValue);
48
+ (0, $ig234$useFormValidation)(props, validationState, ref);
49
+ (0, $ig234$useEffect)(()=>{
50
+ // This works around a React/Chrome bug that prevents textarea elements from validating when controlled.
51
+ // We prevent React from updating defaultValue (i.e. children) of textarea when `value` changes,
52
+ // which causes Chrome to skip validation. Only updating `value` is ok in our case since our
53
+ // textareas are always controlled. React is planning on removing this synchronization in a
54
+ // future major version.
55
+ // https://github.com/facebook/react/issues/19474
56
+ // https://github.com/facebook/react/issues/11896
57
+ if (ref.current instanceof (0, $ig234$getOwnerWindow)(ref.current).HTMLTextAreaElement) {
58
+ let input = ref.current;
59
+ Object.defineProperty(input, "defaultValue", {
60
+ get: ()=>input.value,
61
+ set: ()=>{},
62
+ configurable: true
63
+ });
64
+ }
65
+ }, [
66
+ ref
67
+ ]);
68
+ return {
69
+ labelProps: labelProps,
70
+ inputProps: (0, $ig234$mergeProps)(domProps, inputElementType === "input" && inputOnlyProps, {
71
+ disabled: isDisabled,
72
+ readOnly: isReadOnly,
73
+ required: isRequired && validationBehavior === "native",
74
+ "aria-required": isRequired && validationBehavior === "aria" || undefined,
75
+ "aria-invalid": isInvalid || undefined,
76
+ "aria-errormessage": props["aria-errormessage"],
77
+ "aria-activedescendant": props["aria-activedescendant"],
78
+ "aria-autocomplete": props["aria-autocomplete"],
79
+ "aria-haspopup": props["aria-haspopup"],
80
+ value: value,
81
+ onChange: (e)=>setValue(e.target.value),
82
+ autoComplete: props.autoComplete,
83
+ autoCapitalize: props.autoCapitalize,
84
+ maxLength: props.maxLength,
85
+ minLength: props.minLength,
86
+ name: props.name,
87
+ placeholder: props.placeholder,
88
+ inputMode: props.inputMode,
89
+ // Clipboard events
90
+ onCopy: props.onCopy,
91
+ onCut: props.onCut,
92
+ onPaste: props.onPaste,
93
+ // Composition events
94
+ onCompositionEnd: props.onCompositionEnd,
95
+ onCompositionStart: props.onCompositionStart,
96
+ onCompositionUpdate: props.onCompositionUpdate,
97
+ // Selection events
98
+ onSelect: props.onSelect,
99
+ // Input events
100
+ onBeforeInput: props.onBeforeInput,
101
+ onInput: props.onInput,
102
+ ...focusableProps,
103
+ ...fieldProps
104
+ }),
105
+ descriptionProps: descriptionProps,
106
+ errorMessageProps: errorMessageProps,
107
+ isInvalid: isInvalid,
108
+ validationErrors: validationErrors,
109
+ validationDetails: validationDetails
110
+ };
111
+ }
112
+
113
+
114
+ export {$2d73ec29415bd339$export$712718f7aec83d5 as useTextField};
115
+ //# sourceMappingURL=useTextField.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAsGM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,aACb,OAAO,4BACP,qBAAqB,QACtB,GAAqD;IACtD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,yBAAiB,EAAU,MAAM,KAAK,EAAE,MAAM,YAAY,IAAI,IAAI,MAAM,QAAQ;IACxG,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,OAAO;IAC3C,IAAI,kBAAkB,CAAA,GAAA,6BAAqB,EAAE;QAC3C,GAAG,KAAK;eACR;IACF;IACA,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,gBAAgB,iBAAiB;IACxF,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC3E,GAAG,KAAK;mBACR;QACA,cAAc,MAAM,YAAY,IAAI;IACtC;IACA,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,MAAM,iBAAiB;cACrB;QACA,SAAS,MAAM,OAAO;IACxB;IAEA,CAAA,GAAA,mBAAW,EAAE,KAAK,OAAO;IACzB,CAAA,GAAA,wBAAgB,EAAE,OAAO,iBAAiB;IAE1C,CAAA,GAAA,gBAAQ,EAAE;QACR,wGAAwG;QACxG,gGAAgG;QAChG,4FAA4F;QAC5F,2FAA2F;QAC3F,wBAAwB;QACxB,iDAAiD;QACjD,iDAAiD;QACjD,IAAI,IAAI,OAAO,YAAY,CAAA,GAAA,qBAAa,EAAE,IAAI,OAAO,EAAE,mBAAmB,EAAE;YAC1E,IAAI,QAAQ,IAAI,OAAO;YACvB,OAAO,cAAc,CAAC,OAAO,gBAAgB;gBAC3C,KAAK,IAAM,MAAM,KAAK;gBACtB,KAAK,KAAO;gBACZ,cAAc;YAChB;QACF;IACF,GAAG;QAAC;KAAI;IAER,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,iBAAS,EACnB,UACA,qBAAqB,WAAW,gBAChC;YACE,UAAU;YACV,UAAU;YACV,UAAU,cAAc,uBAAuB;YAC/C,iBAAiB,AAAC,cAAc,uBAAuB,UAAW;YAClE,gBAAgB,aAAa;YAC7B,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,yBAAyB,KAAK,CAAC,wBAAwB;YACvD,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;mBACvC;YACA,UAAU,CAAC,IAAqC,SAAS,EAAE,MAAM,CAAC,KAAK;YACvE,cAAc,MAAM,YAAY;YAChC,gBAAgB,MAAM,cAAc;YACpC,WAAW,MAAM,SAAS;YAC1B,WAAW,MAAM,SAAS;YAC1B,MAAM,MAAM,IAAI;YAChB,aAAa,MAAM,WAAW;YAC9B,WAAW,MAAM,SAAS;YAE1B,mBAAmB;YACnB,QAAQ,MAAM,MAAM;YACpB,OAAO,MAAM,KAAK;YAClB,SAAS,MAAM,OAAO;YAEtB,qBAAqB;YACrB,kBAAkB,MAAM,gBAAgB;YACxC,oBAAoB,MAAM,kBAAkB;YAC5C,qBAAqB,MAAM,mBAAmB;YAE9C,mBAAmB;YACnB,UAAU,MAAM,QAAQ;YAExB,eAAe;YACf,eAAe,MAAM,aAAa;YAClC,SAAS,MAAM,OAAO;YACtB,GAAG,cAAc;YACjB,GAAG,UAAU;QACf;0BAEF;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/textfield/src/useTextField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {\n ChangeEvent,\n DOMFactory,\n HTMLAttributes,\n LabelHTMLAttributes,\n ReactDOM,\n RefObject,\n useEffect\n} from 'react';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, getOwnerWindow, mergeProps, useFormReset} from '@react-aria/utils';\nimport {useControlledState} from '@react-stately/utils';\nimport {useField} from '@react-aria/label';\nimport {useFocusable} from '@react-aria/focus';\nimport {useFormValidation} from '@react-aria/form';\nimport {useFormValidationState} from '@react-stately/form';\n\n/**\n * A map of HTML element names and their interface types.\n * For example `'a'` -> `HTMLAnchorElement`.\n */\ntype IntrinsicHTMLElements = {\n [K in keyof IntrinsicHTMLAttributes]: IntrinsicHTMLAttributes[K] extends HTMLAttributes<infer T> ? T : never\n};\n\n/**\n * A map of HTML element names and their attribute interface types.\n * For example `'a'` -> `AnchorHTMLAttributes<HTMLAnchorElement>`.\n */\ntype IntrinsicHTMLAttributes = {\n [K in keyof ReactDOM]: ReactDOM[K] extends DOMFactory<infer T, any> ? T : never\n};\n\ntype DefaultElementType = 'input';\n\n/**\n * The intrinsic HTML element names that `useTextField` supports; e.g. `input`,\n * `textarea`.\n */\ntype TextFieldIntrinsicElements = keyof Pick<IntrinsicHTMLElements, 'input' | 'textarea'>;\n\n/**\n * The HTML element interfaces that `useTextField` supports based on what is\n * defined for `TextFieldIntrinsicElements`; e.g. `HTMLInputElement`,\n * `HTMLTextAreaElement`.\n */\ntype TextFieldHTMLElementType = Pick<IntrinsicHTMLElements, TextFieldIntrinsicElements>;\n\n/**\n * The HTML attributes interfaces that `useTextField` supports based on what\n * is defined for `TextFieldIntrinsicElements`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldHTMLAttributesType = Pick<IntrinsicHTMLAttributes, TextFieldIntrinsicElements>;\n\n/**\n * The type of `inputProps` returned by `useTextField`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldInputProps<T extends TextFieldIntrinsicElements> = TextFieldHTMLAttributesType[T];\n\nexport interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps {\n /**\n * The HTML element used to render the input, e.g. 'input', or 'textarea'.\n * It determines whether certain HTML attributes will be included in `inputProps`.\n * For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).\n * @default 'input'\n */\n inputElementType?: T,\n /**\n * Controls whether inputted text is automatically capitalized and, if so, in what manner. \n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize).\n */\n autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'\n}\n\n/**\n * The type of `ref` object that can be passed to `useTextField` based on the given\n * intrinsic HTML element name; e.g.`RefObject<HTMLInputElement>`,\n * `RefObject<HTMLTextAreaElement>`.\n */\ntype TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T]>;\n\nexport interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> extends ValidationResult {\n /** Props for the input element. */\n inputProps: TextFieldInputProps<T>,\n /** Props for the text field's visible label element, if any. */\n labelProps: DOMAttributes | LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the text field's description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the text field's error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a text field.\n * @param props - Props for the text field.\n * @param ref - Ref to the HTML input or textarea element.\n */\nexport function useTextField<T extends TextFieldIntrinsicElements = DefaultElementType>(\n props: AriaTextFieldOptions<T>,\n ref: TextFieldRefObject<T>\n): TextFieldAria<T> {\n let {\n inputElementType = 'input',\n isDisabled = false,\n isRequired = false,\n isReadOnly = false,\n type = 'text',\n validationBehavior = 'aria'\n }: AriaTextFieldOptions<TextFieldIntrinsicElements> = props;\n let [value, setValue] = useControlledState<string>(props.value, props.defaultValue || '', props.onChange);\n let {focusableProps} = useFocusable(props, ref);\n let validationState = useFormValidationState({\n ...props,\n value\n });\n let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n let domProps = filterDOMProps(props, {labelable: true});\n\n const inputOnlyProps = {\n type,\n pattern: props.pattern\n };\n\n useFormReset(ref, value, setValue);\n useFormValidation(props, validationState, ref);\n\n useEffect(() => {\n // This works around a React/Chrome bug that prevents textarea elements from validating when controlled.\n // We prevent React from updating defaultValue (i.e. children) of textarea when `value` changes,\n // which causes Chrome to skip validation. Only updating `value` is ok in our case since our\n // textareas are always controlled. React is planning on removing this synchronization in a\n // future major version.\n // https://github.com/facebook/react/issues/19474\n // https://github.com/facebook/react/issues/11896\n if (ref.current instanceof getOwnerWindow(ref.current).HTMLTextAreaElement) {\n let input = ref.current;\n Object.defineProperty(input, 'defaultValue', {\n get: () => input.value,\n set: () => {},\n configurable: true\n });\n }\n }, [ref]);\n\n return {\n labelProps,\n inputProps: mergeProps(\n domProps,\n inputElementType === 'input' && inputOnlyProps,\n {\n disabled: isDisabled,\n readOnly: isReadOnly,\n required: isRequired && validationBehavior === 'native',\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n 'aria-invalid': isInvalid || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-activedescendant': props['aria-activedescendant'],\n 'aria-autocomplete': props['aria-autocomplete'],\n 'aria-haspopup': props['aria-haspopup'],\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),\n autoComplete: props.autoComplete,\n autoCapitalize: props.autoCapitalize,\n maxLength: props.maxLength,\n minLength: props.minLength,\n name: props.name,\n placeholder: props.placeholder,\n inputMode: props.inputMode,\n\n // Clipboard events\n onCopy: props.onCopy,\n onCut: props.onCut,\n onPaste: props.onPaste,\n\n // Composition events\n onCompositionEnd: props.onCompositionEnd,\n onCompositionStart: props.onCompositionStart,\n onCompositionUpdate: props.onCompositionUpdate,\n\n // Selection events\n onSelect: props.onSelect,\n\n // Input events\n onBeforeInput: props.onBeforeInput,\n onInput: props.onInput,\n ...focusableProps,\n ...fieldProps\n }\n ),\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useTextField.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/textfield",
3
- "version": "3.14.3",
3
+ "version": "3.14.4",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,14 +22,14 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "^3.16.2",
26
- "@react-aria/form": "^3.0.3",
27
- "@react-aria/label": "^3.7.6",
28
- "@react-aria/utils": "^3.23.2",
29
- "@react-stately/form": "^3.0.1",
30
- "@react-stately/utils": "^3.9.1",
31
- "@react-types/shared": "^3.22.1",
32
- "@react-types/textfield": "^3.9.1",
25
+ "@react-aria/focus": "^3.17.0",
26
+ "@react-aria/form": "^3.0.4",
27
+ "@react-aria/label": "^3.7.7",
28
+ "@react-aria/utils": "^3.24.0",
29
+ "@react-stately/form": "^3.0.2",
30
+ "@react-stately/utils": "^3.10.0",
31
+ "@react-types/shared": "^3.23.0",
32
+ "@react-types/textfield": "^3.9.2",
33
33
  "@swc/helpers": "^0.5.0"
34
34
  },
35
35
  "peerDependencies": {
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "de9f84a22583fc741c29b341d14cd35ef4cca161"
41
+ "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
42
42
  }
@@ -47,6 +47,9 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
47
47
  // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,
48
48
  // because presumably the input would have already been validated previously.
49
49
  return;
50
+ case 'insertLineBreak':
51
+ // Explicitly allow "insertLineBreak" event, to allow onSubmit for "enter" key. e.data is null in this case.
52
+ return;
50
53
  case 'deleteContent':
51
54
  case 'deleteByCut':
52
55
  case 'deleteByDrag':