@react-aria/textfield 3.12.2 → 3.14.0
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.
- package/dist/import.mjs +55 -14
- package/dist/main.js +55 -13
- package/dist/main.js.map +1 -1
- package/dist/module.js +55 -14
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +7 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -7
- package/src/useFormattedTextField.ts +3 -2
- package/src/useTextField.ts +56 -18
package/dist/import.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {useEffect as $kOq5K$useEffect, useRef as $kOq5K$useRef} from "react";
|
|
2
|
+
import {filterDOMProps as $kOq5K$filterDOMProps, useFormReset as $kOq5K$useFormReset, getOwnerWindow as $kOq5K$getOwnerWindow, mergeProps as $kOq5K$mergeProps, useEffectEvent as $kOq5K$useEffectEvent} from "@react-aria/utils";
|
|
3
|
+
import {useControlledState as $kOq5K$useControlledState} from "@react-stately/utils";
|
|
2
4
|
import {useField as $kOq5K$useField} from "@react-aria/label";
|
|
3
5
|
import {useFocusable as $kOq5K$useFocusable} from "@react-aria/focus";
|
|
4
|
-
import {
|
|
6
|
+
import {useFormValidation as $kOq5K$useFormValidation} from "@react-aria/form";
|
|
7
|
+
import {useFormValidationState as $kOq5K$useFormValidationState} from "@react-stately/form";
|
|
5
8
|
|
|
6
9
|
/*
|
|
7
10
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -26,10 +29,24 @@ import {useEffect as $kOq5K$useEffect, useRef as $kOq5K$useRef} from "react";
|
|
|
26
29
|
*/
|
|
27
30
|
|
|
28
31
|
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
29
36
|
function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
30
|
-
let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false,
|
|
37
|
+
let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, type: type = "text", validationBehavior: validationBehavior = "aria" } = props;
|
|
38
|
+
let [value, setValue] = (0, $kOq5K$useControlledState)(props.value, props.defaultValue || "", props.onChange);
|
|
31
39
|
let { focusableProps: focusableProps } = (0, $kOq5K$useFocusable)(props, ref);
|
|
32
|
-
let
|
|
40
|
+
let validationState = (0, $kOq5K$useFormValidationState)({
|
|
41
|
+
...props,
|
|
42
|
+
value: value
|
|
43
|
+
});
|
|
44
|
+
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
|
|
45
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $kOq5K$useField)({
|
|
46
|
+
...props,
|
|
47
|
+
isInvalid: isInvalid,
|
|
48
|
+
errorMessage: props.errorMessage || validationErrors
|
|
49
|
+
});
|
|
33
50
|
let domProps = (0, $kOq5K$filterDOMProps)(props, {
|
|
34
51
|
labelable: true
|
|
35
52
|
});
|
|
@@ -37,23 +54,43 @@ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
|
37
54
|
type: type,
|
|
38
55
|
pattern: props.pattern
|
|
39
56
|
};
|
|
40
|
-
|
|
41
|
-
(0, $kOq5K$
|
|
57
|
+
(0, $kOq5K$useFormReset)(ref, value, setValue);
|
|
58
|
+
(0, $kOq5K$useFormValidation)(props, validationState, ref);
|
|
59
|
+
(0, $kOq5K$useEffect)(()=>{
|
|
60
|
+
// This works around a React/Chrome bug that prevents textarea elements from validating when controlled.
|
|
61
|
+
// We prevent React from updating defaultValue (i.e. children) of textarea when `value` changes,
|
|
62
|
+
// which causes Chrome to skip validation. Only updating `value` is ok in our case since our
|
|
63
|
+
// textareas are always controlled. React is planning on removing this synchronization in a
|
|
64
|
+
// future major version.
|
|
65
|
+
// https://github.com/facebook/react/issues/19474
|
|
66
|
+
// https://github.com/facebook/react/issues/11896
|
|
67
|
+
if (ref.current instanceof (0, $kOq5K$getOwnerWindow)(ref.current).HTMLTextAreaElement) {
|
|
68
|
+
let input = ref.current;
|
|
69
|
+
Object.defineProperty(input, "defaultValue", {
|
|
70
|
+
get: ()=>input.value,
|
|
71
|
+
set: ()=>{},
|
|
72
|
+
configurable: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}, [
|
|
76
|
+
ref
|
|
77
|
+
]);
|
|
42
78
|
return {
|
|
43
79
|
labelProps: labelProps,
|
|
44
80
|
inputProps: (0, $kOq5K$mergeProps)(domProps, inputElementType === "input" && inputOnlyProps, {
|
|
45
81
|
disabled: isDisabled,
|
|
46
82
|
readOnly: isReadOnly,
|
|
47
|
-
|
|
48
|
-
"aria-
|
|
83
|
+
required: isRequired && validationBehavior === "native",
|
|
84
|
+
"aria-required": isRequired && validationBehavior === "aria" || undefined,
|
|
85
|
+
"aria-invalid": isInvalid || undefined,
|
|
49
86
|
"aria-errormessage": props["aria-errormessage"],
|
|
50
87
|
"aria-activedescendant": props["aria-activedescendant"],
|
|
51
88
|
"aria-autocomplete": props["aria-autocomplete"],
|
|
52
89
|
"aria-haspopup": props["aria-haspopup"],
|
|
53
|
-
value:
|
|
54
|
-
|
|
55
|
-
onChange: (e)=>onChange(e.target.value),
|
|
90
|
+
value: value,
|
|
91
|
+
onChange: (e)=>setValue(e.target.value),
|
|
56
92
|
autoComplete: props.autoComplete,
|
|
93
|
+
autoCapitalize: props.autoCapitalize,
|
|
57
94
|
maxLength: props.maxLength,
|
|
58
95
|
minLength: props.minLength,
|
|
59
96
|
name: props.name,
|
|
@@ -76,7 +113,10 @@ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
|
76
113
|
...fieldProps
|
|
77
114
|
}),
|
|
78
115
|
descriptionProps: descriptionProps,
|
|
79
|
-
errorMessageProps: errorMessageProps
|
|
116
|
+
errorMessageProps: errorMessageProps,
|
|
117
|
+
isInvalid: isInvalid,
|
|
118
|
+
validationErrors: validationErrors,
|
|
119
|
+
validationDetails: validationDetails
|
|
80
120
|
};
|
|
81
121
|
}
|
|
82
122
|
|
|
@@ -159,7 +199,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
159
199
|
let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
|
|
160
200
|
if (!state.validate(nextValue)) e.preventDefault();
|
|
161
201
|
} : null;
|
|
162
|
-
let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
|
|
202
|
+
let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps, ...validation } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
|
|
163
203
|
let compositionStartState = (0, $kOq5K$useRef)(null);
|
|
164
204
|
return {
|
|
165
205
|
inputProps: (0, $kOq5K$mergeProps)(textFieldProps, {
|
|
@@ -197,7 +237,8 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
197
237
|
}),
|
|
198
238
|
labelProps: labelProps,
|
|
199
239
|
descriptionProps: descriptionProps,
|
|
200
|
-
errorMessageProps: errorMessageProps
|
|
240
|
+
errorMessageProps: errorMessageProps,
|
|
241
|
+
...validation
|
|
201
242
|
};
|
|
202
243
|
}
|
|
203
244
|
|
package/dist/main.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
var $iITAC$react = require("react");
|
|
1
2
|
var $iITAC$reactariautils = require("@react-aria/utils");
|
|
3
|
+
var $iITAC$reactstatelyutils = require("@react-stately/utils");
|
|
2
4
|
var $iITAC$reactarialabel = require("@react-aria/label");
|
|
3
5
|
var $iITAC$reactariafocus = require("@react-aria/focus");
|
|
4
|
-
var $iITAC$
|
|
6
|
+
var $iITAC$reactariaform = require("@react-aria/form");
|
|
7
|
+
var $iITAC$reactstatelyform = require("@react-stately/form");
|
|
8
|
+
|
|
5
9
|
|
|
6
10
|
function $parcel$export(e, n, v, s) {
|
|
7
11
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
@@ -32,10 +36,24 @@ $parcel$export(module.exports, "useFormattedTextField", () => $56b68c3dab9bf16c$
|
|
|
32
36
|
*/
|
|
33
37
|
|
|
34
38
|
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
35
43
|
function $9076f978e02df845$export$712718f7aec83d5(props, ref) {
|
|
36
|
-
let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false,
|
|
44
|
+
let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, type: type = "text", validationBehavior: validationBehavior = "aria" } = props;
|
|
45
|
+
let [value, setValue] = (0, $iITAC$reactstatelyutils.useControlledState)(props.value, props.defaultValue || "", props.onChange);
|
|
37
46
|
let { focusableProps: focusableProps } = (0, $iITAC$reactariafocus.useFocusable)(props, ref);
|
|
38
|
-
let
|
|
47
|
+
let validationState = (0, $iITAC$reactstatelyform.useFormValidationState)({
|
|
48
|
+
...props,
|
|
49
|
+
value: value
|
|
50
|
+
});
|
|
51
|
+
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
|
|
52
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $iITAC$reactarialabel.useField)({
|
|
53
|
+
...props,
|
|
54
|
+
isInvalid: isInvalid,
|
|
55
|
+
errorMessage: props.errorMessage || validationErrors
|
|
56
|
+
});
|
|
39
57
|
let domProps = (0, $iITAC$reactariautils.filterDOMProps)(props, {
|
|
40
58
|
labelable: true
|
|
41
59
|
});
|
|
@@ -43,23 +61,43 @@ function $9076f978e02df845$export$712718f7aec83d5(props, ref) {
|
|
|
43
61
|
type: type,
|
|
44
62
|
pattern: props.pattern
|
|
45
63
|
};
|
|
46
|
-
|
|
47
|
-
(0, $iITAC$
|
|
64
|
+
(0, $iITAC$reactariautils.useFormReset)(ref, value, setValue);
|
|
65
|
+
(0, $iITAC$reactariaform.useFormValidation)(props, validationState, ref);
|
|
66
|
+
(0, $iITAC$react.useEffect)(()=>{
|
|
67
|
+
// This works around a React/Chrome bug that prevents textarea elements from validating when controlled.
|
|
68
|
+
// We prevent React from updating defaultValue (i.e. children) of textarea when `value` changes,
|
|
69
|
+
// which causes Chrome to skip validation. Only updating `value` is ok in our case since our
|
|
70
|
+
// textareas are always controlled. React is planning on removing this synchronization in a
|
|
71
|
+
// future major version.
|
|
72
|
+
// https://github.com/facebook/react/issues/19474
|
|
73
|
+
// https://github.com/facebook/react/issues/11896
|
|
74
|
+
if (ref.current instanceof (0, $iITAC$reactariautils.getOwnerWindow)(ref.current).HTMLTextAreaElement) {
|
|
75
|
+
let input = ref.current;
|
|
76
|
+
Object.defineProperty(input, "defaultValue", {
|
|
77
|
+
get: ()=>input.value,
|
|
78
|
+
set: ()=>{},
|
|
79
|
+
configurable: true
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, [
|
|
83
|
+
ref
|
|
84
|
+
]);
|
|
48
85
|
return {
|
|
49
86
|
labelProps: labelProps,
|
|
50
87
|
inputProps: (0, $iITAC$reactariautils.mergeProps)(domProps, inputElementType === "input" && inputOnlyProps, {
|
|
51
88
|
disabled: isDisabled,
|
|
52
89
|
readOnly: isReadOnly,
|
|
53
|
-
|
|
54
|
-
"aria-
|
|
90
|
+
required: isRequired && validationBehavior === "native",
|
|
91
|
+
"aria-required": isRequired && validationBehavior === "aria" || undefined,
|
|
92
|
+
"aria-invalid": isInvalid || undefined,
|
|
55
93
|
"aria-errormessage": props["aria-errormessage"],
|
|
56
94
|
"aria-activedescendant": props["aria-activedescendant"],
|
|
57
95
|
"aria-autocomplete": props["aria-autocomplete"],
|
|
58
96
|
"aria-haspopup": props["aria-haspopup"],
|
|
59
|
-
value:
|
|
60
|
-
|
|
61
|
-
onChange: (e)=>onChange(e.target.value),
|
|
97
|
+
value: value,
|
|
98
|
+
onChange: (e)=>setValue(e.target.value),
|
|
62
99
|
autoComplete: props.autoComplete,
|
|
100
|
+
autoCapitalize: props.autoCapitalize,
|
|
63
101
|
maxLength: props.maxLength,
|
|
64
102
|
minLength: props.minLength,
|
|
65
103
|
name: props.name,
|
|
@@ -82,7 +120,10 @@ function $9076f978e02df845$export$712718f7aec83d5(props, ref) {
|
|
|
82
120
|
...fieldProps
|
|
83
121
|
}),
|
|
84
122
|
descriptionProps: descriptionProps,
|
|
85
|
-
errorMessageProps: errorMessageProps
|
|
123
|
+
errorMessageProps: errorMessageProps,
|
|
124
|
+
isInvalid: isInvalid,
|
|
125
|
+
validationErrors: validationErrors,
|
|
126
|
+
validationDetails: validationDetails
|
|
86
127
|
};
|
|
87
128
|
}
|
|
88
129
|
|
|
@@ -165,7 +206,7 @@ function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
165
206
|
let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
|
|
166
207
|
if (!state.validate(nextValue)) e.preventDefault();
|
|
167
208
|
} : null;
|
|
168
|
-
let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $9076f978e02df845$export$712718f7aec83d5)(props, inputRef);
|
|
209
|
+
let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps, ...validation } = (0, $9076f978e02df845$export$712718f7aec83d5)(props, inputRef);
|
|
169
210
|
let compositionStartState = (0, $iITAC$react.useRef)(null);
|
|
170
211
|
return {
|
|
171
212
|
inputProps: (0, $iITAC$reactariautils.mergeProps)(textFieldProps, {
|
|
@@ -203,7 +244,8 @@ function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
203
244
|
}),
|
|
204
245
|
labelProps: labelProps,
|
|
205
246
|
descriptionProps: descriptionProps,
|
|
206
|
-
errorMessageProps: errorMessageProps
|
|
247
|
+
errorMessageProps: errorMessageProps,
|
|
248
|
+
...validation
|
|
207
249
|
};
|
|
208
250
|
}
|
|
209
251
|
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6FM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,wBACb,eAAe,aACf,YAAY,aACZ,OAAO,eACP,KAAK,gBACL,YAAY,YACZ,WAAW,KAAO,GACnB,GAAqD;IACtD,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;IAC7E,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,MAAM,iBAAiB;cACrB;QACA,SAAS,MAAM;IACjB;QAEkB;IAAlB,CAAA,GAAA,kCAAW,EAAE,KAAK,CAAA,OAAA,kBAAA,mBAAA,QAAS,0BAAT,kBAAA,OAAyB,IAAI;IAE/C,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,gCAAS,EACnB,UACA,qBAAqB,WAAW,gBAChC;YACE,UAAU;YACV,UAAU;YACV,iBAAiB,cAAc;YAC/B,gBAAgB,aAAa,oBAAoB,aAAa;YAC9D,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,yBAAyB,KAAK,CAAC,wBAAwB;YACvD,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;YACvC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A;gBACE,4FAA4F;gBAC5F,+FAA+F;gBAC/F,gGAAgG;gBAChG,kGAAkG;gBAClG,gGAAgG;gBAChG,mGAAmG;gBACnG,oGAAoG;gBACpG,kGAAkG;gBAClG,qGAAqG;gBACrG,yGAAyG;gBACzG,oEAAoE;gBACpE,oEAAoE;gBACpE,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,SAAS;gBACrD,sBAAsB,UAAU;2BAAC;oCAAO;kCAAgB;gBAAY;YACtE;YACA;gBACE,IAAI,CAAC,MAAM,SAAS,SAAS,QAAQ,QAAQ;oBAC3C,wGAAwG;oBACxG,wFAAwF;oBACxF,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,sBAAsB;oBAClE,SAAS,QAAQ,QAAQ;oBACzB,SAAS,QAAQ,kBAAkB,gBAAgB;oBACnD,MAAM,cAAc;gBACtB;YACF;QACF;oBAEF;0BACA;2BACA;IACF;AACF;","sources":["packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/useFormattedTextField.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 */\nexport type {TextFieldAria} from './useTextField';\nexport {useTextField} from './useTextField';\nexport {useFormattedTextField} from './useFormattedTextField';\nexport type {AriaTextFieldOptions} from './useTextField';\nexport type {AriaTextFieldProps} from '@react-types/textfield';\n","/*\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} from 'react';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\nimport {useFocusable} from '@react-aria/focus';\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\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> {\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 validationState,\n isInvalid = false,\n type = 'text',\n value,\n defaultValue,\n onChange = () => {}\n }: AriaTextFieldOptions<TextFieldIntrinsicElements> = props;\n let {focusableProps} = useFocusable(props, ref);\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField(props);\n let domProps = filterDOMProps(props, {labelable: true});\n\n const inputOnlyProps = {\n type,\n pattern: props.pattern\n };\n\n useFormReset(ref, value ?? defaultValue ?? '', onChange);\n\n return {\n labelProps,\n inputProps: mergeProps(\n domProps,\n inputElementType === 'input' && inputOnlyProps,\n {\n disabled: isDisabled,\n readOnly: isReadOnly,\n 'aria-required': isRequired || undefined,\n 'aria-invalid': isInvalid || validationState === 'invalid' || 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: props.value,\n defaultValue: props.value ? undefined : props.defaultValue,\n onChange: (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.value),\n autoComplete: props.autoComplete,\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 };\n}\n","/*\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 '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} = 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 };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;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;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EvH,IAAI,wBAAwB,CAAA,GAAA,mBAAK,EAAE;IACnC,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EACnB,gBACA;2BACE;YACA;gBACE,4FAA4F;gBAC5F,+FAA+F;gBAC/F,gGAAgG;gBAChG,kGAAkG;gBAClG,gGAAgG;gBAChG,mGAAmG;gBACnG,oGAAoG;gBACpG,kGAAkG;gBAClG,qGAAqG;gBACrG,yGAAyG;gBACzG,oEAAoE;gBACpE,oEAAoE;gBACpE,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,SAAS,OAAO;gBAC5D,sBAAsB,OAAO,GAAG;2BAAC;oCAAO;kCAAgB;gBAAY;YACtE;YACA;gBACE,IAAI,CAAC,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC,KAAK,GAAG;oBAC3C,wGAAwG;oBACxG,wFAAwF;oBACxF,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,sBAAsB,OAAO;oBACzE,SAAS,OAAO,CAAC,KAAK,GAAG;oBACzB,SAAS,OAAO,CAAC,iBAAiB,CAAC,gBAAgB;oBACnD,MAAM,aAAa,CAAC;gBACtB;YACF;QACF;oBAEF;0BACA;2BACA;QACA,GAAG,UAAU;IACf;AACF;","sources":["packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/useFormattedTextField.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 */\nexport type {TextFieldAria} from './useTextField';\nexport {useTextField} from './useTextField';\nexport {useFormattedTextField} from './useFormattedTextField';\nexport type {AriaTextFieldOptions} from './useTextField';\nexport type {AriaTextFieldProps} from '@react-types/textfield';\n","/*\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 * A nonstandard attribute used by iOS Safari that controls how textual form elements should be automatically capitalized.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#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","/*\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 '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":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {useEffect as $kOq5K$useEffect, useRef as $kOq5K$useRef} from "react";
|
|
2
|
+
import {filterDOMProps as $kOq5K$filterDOMProps, useFormReset as $kOq5K$useFormReset, getOwnerWindow as $kOq5K$getOwnerWindow, mergeProps as $kOq5K$mergeProps, useEffectEvent as $kOq5K$useEffectEvent} from "@react-aria/utils";
|
|
3
|
+
import {useControlledState as $kOq5K$useControlledState} from "@react-stately/utils";
|
|
2
4
|
import {useField as $kOq5K$useField} from "@react-aria/label";
|
|
3
5
|
import {useFocusable as $kOq5K$useFocusable} from "@react-aria/focus";
|
|
4
|
-
import {
|
|
6
|
+
import {useFormValidation as $kOq5K$useFormValidation} from "@react-aria/form";
|
|
7
|
+
import {useFormValidationState as $kOq5K$useFormValidationState} from "@react-stately/form";
|
|
5
8
|
|
|
6
9
|
/*
|
|
7
10
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -26,10 +29,24 @@ import {useEffect as $kOq5K$useEffect, useRef as $kOq5K$useRef} from "react";
|
|
|
26
29
|
*/
|
|
27
30
|
|
|
28
31
|
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
29
36
|
function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
30
|
-
let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false,
|
|
37
|
+
let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, type: type = "text", validationBehavior: validationBehavior = "aria" } = props;
|
|
38
|
+
let [value, setValue] = (0, $kOq5K$useControlledState)(props.value, props.defaultValue || "", props.onChange);
|
|
31
39
|
let { focusableProps: focusableProps } = (0, $kOq5K$useFocusable)(props, ref);
|
|
32
|
-
let
|
|
40
|
+
let validationState = (0, $kOq5K$useFormValidationState)({
|
|
41
|
+
...props,
|
|
42
|
+
value: value
|
|
43
|
+
});
|
|
44
|
+
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
|
|
45
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $kOq5K$useField)({
|
|
46
|
+
...props,
|
|
47
|
+
isInvalid: isInvalid,
|
|
48
|
+
errorMessage: props.errorMessage || validationErrors
|
|
49
|
+
});
|
|
33
50
|
let domProps = (0, $kOq5K$filterDOMProps)(props, {
|
|
34
51
|
labelable: true
|
|
35
52
|
});
|
|
@@ -37,23 +54,43 @@ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
|
37
54
|
type: type,
|
|
38
55
|
pattern: props.pattern
|
|
39
56
|
};
|
|
40
|
-
|
|
41
|
-
(0, $kOq5K$
|
|
57
|
+
(0, $kOq5K$useFormReset)(ref, value, setValue);
|
|
58
|
+
(0, $kOq5K$useFormValidation)(props, validationState, ref);
|
|
59
|
+
(0, $kOq5K$useEffect)(()=>{
|
|
60
|
+
// This works around a React/Chrome bug that prevents textarea elements from validating when controlled.
|
|
61
|
+
// We prevent React from updating defaultValue (i.e. children) of textarea when `value` changes,
|
|
62
|
+
// which causes Chrome to skip validation. Only updating `value` is ok in our case since our
|
|
63
|
+
// textareas are always controlled. React is planning on removing this synchronization in a
|
|
64
|
+
// future major version.
|
|
65
|
+
// https://github.com/facebook/react/issues/19474
|
|
66
|
+
// https://github.com/facebook/react/issues/11896
|
|
67
|
+
if (ref.current instanceof (0, $kOq5K$getOwnerWindow)(ref.current).HTMLTextAreaElement) {
|
|
68
|
+
let input = ref.current;
|
|
69
|
+
Object.defineProperty(input, "defaultValue", {
|
|
70
|
+
get: ()=>input.value,
|
|
71
|
+
set: ()=>{},
|
|
72
|
+
configurable: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}, [
|
|
76
|
+
ref
|
|
77
|
+
]);
|
|
42
78
|
return {
|
|
43
79
|
labelProps: labelProps,
|
|
44
80
|
inputProps: (0, $kOq5K$mergeProps)(domProps, inputElementType === "input" && inputOnlyProps, {
|
|
45
81
|
disabled: isDisabled,
|
|
46
82
|
readOnly: isReadOnly,
|
|
47
|
-
|
|
48
|
-
"aria-
|
|
83
|
+
required: isRequired && validationBehavior === "native",
|
|
84
|
+
"aria-required": isRequired && validationBehavior === "aria" || undefined,
|
|
85
|
+
"aria-invalid": isInvalid || undefined,
|
|
49
86
|
"aria-errormessage": props["aria-errormessage"],
|
|
50
87
|
"aria-activedescendant": props["aria-activedescendant"],
|
|
51
88
|
"aria-autocomplete": props["aria-autocomplete"],
|
|
52
89
|
"aria-haspopup": props["aria-haspopup"],
|
|
53
|
-
value:
|
|
54
|
-
|
|
55
|
-
onChange: (e)=>onChange(e.target.value),
|
|
90
|
+
value: value,
|
|
91
|
+
onChange: (e)=>setValue(e.target.value),
|
|
56
92
|
autoComplete: props.autoComplete,
|
|
93
|
+
autoCapitalize: props.autoCapitalize,
|
|
57
94
|
maxLength: props.maxLength,
|
|
58
95
|
minLength: props.minLength,
|
|
59
96
|
name: props.name,
|
|
@@ -76,7 +113,10 @@ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
|
76
113
|
...fieldProps
|
|
77
114
|
}),
|
|
78
115
|
descriptionProps: descriptionProps,
|
|
79
|
-
errorMessageProps: errorMessageProps
|
|
116
|
+
errorMessageProps: errorMessageProps,
|
|
117
|
+
isInvalid: isInvalid,
|
|
118
|
+
validationErrors: validationErrors,
|
|
119
|
+
validationDetails: validationDetails
|
|
80
120
|
};
|
|
81
121
|
}
|
|
82
122
|
|
|
@@ -159,7 +199,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
159
199
|
let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
|
|
160
200
|
if (!state.validate(nextValue)) e.preventDefault();
|
|
161
201
|
} : null;
|
|
162
|
-
let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
|
|
202
|
+
let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps, ...validation } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
|
|
163
203
|
let compositionStartState = (0, $kOq5K$useRef)(null);
|
|
164
204
|
return {
|
|
165
205
|
inputProps: (0, $kOq5K$mergeProps)(textFieldProps, {
|
|
@@ -197,7 +237,8 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
197
237
|
}),
|
|
198
238
|
labelProps: labelProps,
|
|
199
239
|
descriptionProps: descriptionProps,
|
|
200
|
-
errorMessageProps: errorMessageProps
|
|
240
|
+
errorMessageProps: errorMessageProps,
|
|
241
|
+
...validation
|
|
201
242
|
};
|
|
202
243
|
}
|
|
203
244
|
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6FM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,wBACb,eAAe,aACf,YAAY,aACZ,OAAO,eACP,KAAK,gBACL,YAAY,YACZ,WAAW,KAAO,GACnB,GAAqD;IACtD,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GA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,MAAM,iBAAiB,eAAe,uBAAuB;QAC7D,OAAO;YACL,MAAM,oBAAoB,eAAe,uBAAuB;QAClE;IACF,GAAG;QAAC;QAAU;KAAsB;IAEpC,IAAI,gBAAgB,CAAC,yDACjB,CAAA;QACA,IAAI,YACF,EAAE,OAAO,MAAM,MAAM,GAAG,EAAE,OAAO,kBACjC,EAAE,OACF,EAAE,OAAO,MAAM,MAAM,EAAE,OAAO;QAEhC,IAAI,CAAC,MAAM,SAAS,YAClB,EAAE;IAEN,IACE;IAEJ,IAAI,cAAC,UAAU,EAAE,YAAY,cAAc,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,wCAAW,EAAE,OAAO;IAExG,IAAI,wBAAwB,CAAA,GAAA,aAAK,EAAE;IACnC,OAAO;QACL,YAAY,CAAA,GAAA,iBAAS,EACnB,gBACA;2BACE;YACA;gBACE,4FAA4F;gBAC5F,+FAA+F;gBAC/F,gGAAgG;gBAChG,kGAAkG;gBAClG,gGAAgG;gBAChG,mGAAmG;gBACnG,oGAAoG;gBACpG,kGAAkG;gBAClG,qGAAqG;gBACrG,yGAAyG;gBACzG,oEAAoE;gBACpE,oEAAoE;gBACpE,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,SAAS;gBACrD,sBAAsB,UAAU;2BAAC;oCAAO;kCAAgB;gBAAY;YACtE;YACA;gBACE,IAAI,CAAC,MAAM,SAAS,SAAS,QAAQ,QAAQ;oBAC3C,wGAAwG;oBACxG,wFAAwF;oBACxF,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,sBAAsB;oBAClE,SAAS,QAAQ,QAAQ;oBACzB,SAAS,QAAQ,kBAAkB,gBAAgB;oBACnD,MAAM,cAAc;gBACtB;YACF;QACF;oBAEF;0BACA;2BACA;IACF;AACF;","sources":["packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/useFormattedTextField.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 */\nexport type {TextFieldAria} from './useTextField';\nexport {useTextField} from './useTextField';\nexport {useFormattedTextField} from './useFormattedTextField';\nexport type {AriaTextFieldOptions} from './useTextField';\nexport type {AriaTextFieldProps} from '@react-types/textfield';\n","/*\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} from 'react';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\nimport {useFocusable} from '@react-aria/focus';\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\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> {\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 validationState,\n isInvalid = false,\n type = 'text',\n value,\n defaultValue,\n onChange = () => {}\n }: AriaTextFieldOptions<TextFieldIntrinsicElements> = props;\n let {focusableProps} = useFocusable(props, ref);\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField(props);\n let domProps = filterDOMProps(props, {labelable: true});\n\n const inputOnlyProps = {\n type,\n pattern: props.pattern\n };\n\n useFormReset(ref, value ?? defaultValue ?? '', onChange);\n\n return {\n labelProps,\n inputProps: mergeProps(\n domProps,\n inputElementType === 'input' && inputOnlyProps,\n {\n disabled: isDisabled,\n readOnly: isReadOnly,\n 'aria-required': isRequired || undefined,\n 'aria-invalid': isInvalid || validationState === 'invalid' || 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: props.value,\n defaultValue: props.value ? undefined : props.defaultValue,\n onChange: (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.value),\n autoComplete: props.autoComplete,\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 };\n}\n","/*\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 '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} = 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 };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;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,IAA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,gBAAgB;oBACnD,MAAM,aAAa,CAAC;gBACtB;YACF;QACF;oBAEF;0BACA;2BACA;QACA,GAAG,UAAU;IACf;AACF;","sources":["packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/useFormattedTextField.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 */\nexport type {TextFieldAria} from './useTextField';\nexport {useTextField} from './useTextField';\nexport {useFormattedTextField} from './useFormattedTextField';\nexport type {AriaTextFieldOptions} from './useTextField';\nexport type {AriaTextFieldProps} from '@react-types/textfield';\n","/*\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 * A nonstandard attribute used by iOS Safari that controls how textual form elements should be automatically capitalized.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#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","/*\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 '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":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AriaTextFieldProps } from "@react-types/textfield";
|
|
2
2
|
import { DOMFactory, HTMLAttributes, LabelHTMLAttributes, ReactDOM, RefObject } from "react";
|
|
3
|
-
import { DOMAttributes } from "@react-types/shared";
|
|
3
|
+
import { DOMAttributes, ValidationResult } from "@react-types/shared";
|
|
4
4
|
/**
|
|
5
5
|
* A map of HTML element names and their interface types.
|
|
6
6
|
* For example `'a'` -> `HTMLAnchorElement`.
|
|
@@ -46,6 +46,11 @@ export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> exte
|
|
|
46
46
|
* @default 'input'
|
|
47
47
|
*/
|
|
48
48
|
inputElementType?: T;
|
|
49
|
+
/**
|
|
50
|
+
* A nonstandard attribute used by iOS Safari that controls how textual form elements should be automatically capitalized.
|
|
51
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocapitalize).
|
|
52
|
+
*/
|
|
53
|
+
autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters';
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
56
|
* The type of `ref` object that can be passed to `useTextField` based on the given
|
|
@@ -53,7 +58,7 @@ export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> exte
|
|
|
53
58
|
* `RefObject<HTMLTextAreaElement>`.
|
|
54
59
|
*/
|
|
55
60
|
type TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T]>;
|
|
56
|
-
export interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> {
|
|
61
|
+
export interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> extends ValidationResult {
|
|
57
62
|
/** Props for the input element. */
|
|
58
63
|
inputProps: TextFieldInputProps<T>;
|
|
59
64
|
/** Props for the text field's visible label element, if any. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;
|
|
1
|
+
{"mappings":";;;AA8BA;;;GAGG;AACH,6BAA6B;KAC1B,CAAC,IAAI,MAAM,uBAAuB,GAAG,uBAAuB,CAAC,CAAC,CAAC,SAAS,eAAe,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAC7G,CAAC;AAEF;;;GAGG;AACH,+BAA+B;KAC5B,CAAC,IAAI,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,SAAS,WAAW,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK;CAChF,CAAC;AAEF,0BAA0B,OAAO,CAAC;AAElC;;;GAGG;AACH,kCAAkC,MAAM,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,UAAU,CAAC,CAAC;AAE1F;;;;GAIG;AACH,gCAAgC,IAAI,CAAC,qBAAqB,EAAE,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AAa,CA8HrJ;AC7ID,YAAY,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC","sources":["packages/@react-aria/textfield/src/packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/packages/@react-aria/textfield/src/useFormattedTextField.ts","packages/@react-aria/textfield/src/packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/index.ts"],"sourcesContent":[null,null,null,"/*\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 */\nexport type {TextFieldAria} from './useTextField';\nexport {useTextField} from './useTextField';\nexport {useFormattedTextField} from './useFormattedTextField';\nexport type {AriaTextFieldOptions} from './useTextField';\nexport type {AriaTextFieldProps} from '@react-types/textfield';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/textfield",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,11 +22,14 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/focus": "^3.
|
|
26
|
-
"@react-aria/
|
|
27
|
-
"@react-aria/
|
|
28
|
-
"@react-
|
|
29
|
-
"@react-
|
|
25
|
+
"@react-aria/focus": "^3.16.0",
|
|
26
|
+
"@react-aria/form": "^3.0.1",
|
|
27
|
+
"@react-aria/label": "^3.7.4",
|
|
28
|
+
"@react-aria/utils": "^3.23.0",
|
|
29
|
+
"@react-stately/form": "^3.0.0",
|
|
30
|
+
"@react-stately/utils": "^3.9.0",
|
|
31
|
+
"@react-types/shared": "^3.22.0",
|
|
32
|
+
"@react-types/textfield": "^3.9.0",
|
|
30
33
|
"@swc/helpers": "^0.5.0"
|
|
31
34
|
},
|
|
32
35
|
"peerDependencies": {
|
|
@@ -35,5 +38,5 @@
|
|
|
35
38
|
"publishConfig": {
|
|
36
39
|
"access": "public"
|
|
37
40
|
},
|
|
38
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "86b38c87868ce7f262e0df905e5ac4eb2653791d"
|
|
39
42
|
}
|
|
@@ -113,7 +113,7 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
|
|
|
113
113
|
}
|
|
114
114
|
: null;
|
|
115
115
|
|
|
116
|
-
let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps} = useTextField(props, inputRef);
|
|
116
|
+
let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps, ...validation} = useTextField(props, inputRef);
|
|
117
117
|
|
|
118
118
|
let compositionStartState = useRef(null);
|
|
119
119
|
return {
|
|
@@ -151,6 +151,7 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
|
|
|
151
151
|
),
|
|
152
152
|
labelProps,
|
|
153
153
|
descriptionProps,
|
|
154
|
-
errorMessageProps
|
|
154
|
+
errorMessageProps,
|
|
155
|
+
...validation
|
|
155
156
|
};
|
|
156
157
|
}
|
package/src/useTextField.ts
CHANGED
|
@@ -17,12 +17,16 @@ import {
|
|
|
17
17
|
HTMLAttributes,
|
|
18
18
|
LabelHTMLAttributes,
|
|
19
19
|
ReactDOM,
|
|
20
|
-
RefObject
|
|
20
|
+
RefObject,
|
|
21
|
+
useEffect
|
|
21
22
|
} from 'react';
|
|
22
|
-
import {DOMAttributes} from '@react-types/shared';
|
|
23
|
-
import {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';
|
|
23
|
+
import {DOMAttributes, ValidationResult} from '@react-types/shared';
|
|
24
|
+
import {filterDOMProps, getOwnerWindow, mergeProps, useFormReset} from '@react-aria/utils';
|
|
25
|
+
import {useControlledState} from '@react-stately/utils';
|
|
24
26
|
import {useField} from '@react-aria/label';
|
|
25
27
|
import {useFocusable} from '@react-aria/focus';
|
|
28
|
+
import {useFormValidation} from '@react-aria/form';
|
|
29
|
+
import {useFormValidationState} from '@react-stately/form';
|
|
26
30
|
|
|
27
31
|
/**
|
|
28
32
|
* A map of HTML element names and their interface types.
|
|
@@ -75,7 +79,12 @@ export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> exte
|
|
|
75
79
|
* For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).
|
|
76
80
|
* @default 'input'
|
|
77
81
|
*/
|
|
78
|
-
inputElementType?: T
|
|
82
|
+
inputElementType?: T,
|
|
83
|
+
/**
|
|
84
|
+
* A nonstandard attribute used by iOS Safari that controls how textual form elements should be automatically capitalized.
|
|
85
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocapitalize).
|
|
86
|
+
*/
|
|
87
|
+
autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'
|
|
79
88
|
}
|
|
80
89
|
|
|
81
90
|
/**
|
|
@@ -85,7 +94,7 @@ export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> exte
|
|
|
85
94
|
*/
|
|
86
95
|
type TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T]>;
|
|
87
96
|
|
|
88
|
-
export interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> {
|
|
97
|
+
export interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> extends ValidationResult {
|
|
89
98
|
/** Props for the input element. */
|
|
90
99
|
inputProps: TextFieldInputProps<T>,
|
|
91
100
|
/** Props for the text field's visible label element, if any. */
|
|
@@ -110,15 +119,21 @@ export function useTextField<T extends TextFieldIntrinsicElements = DefaultEleme
|
|
|
110
119
|
isDisabled = false,
|
|
111
120
|
isRequired = false,
|
|
112
121
|
isReadOnly = false,
|
|
113
|
-
validationState,
|
|
114
|
-
isInvalid = false,
|
|
115
122
|
type = 'text',
|
|
116
|
-
|
|
117
|
-
defaultValue,
|
|
118
|
-
onChange = () => {}
|
|
123
|
+
validationBehavior = 'aria'
|
|
119
124
|
}: AriaTextFieldOptions<TextFieldIntrinsicElements> = props;
|
|
125
|
+
let [value, setValue] = useControlledState<string>(props.value, props.defaultValue || '', props.onChange);
|
|
120
126
|
let {focusableProps} = useFocusable(props, ref);
|
|
121
|
-
let
|
|
127
|
+
let validationState = useFormValidationState({
|
|
128
|
+
...props,
|
|
129
|
+
value
|
|
130
|
+
});
|
|
131
|
+
let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;
|
|
132
|
+
let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
|
|
133
|
+
...props,
|
|
134
|
+
isInvalid,
|
|
135
|
+
errorMessage: props.errorMessage || validationErrors
|
|
136
|
+
});
|
|
122
137
|
let domProps = filterDOMProps(props, {labelable: true});
|
|
123
138
|
|
|
124
139
|
const inputOnlyProps = {
|
|
@@ -126,7 +141,26 @@ export function useTextField<T extends TextFieldIntrinsicElements = DefaultEleme
|
|
|
126
141
|
pattern: props.pattern
|
|
127
142
|
};
|
|
128
143
|
|
|
129
|
-
useFormReset(ref, value
|
|
144
|
+
useFormReset(ref, value, setValue);
|
|
145
|
+
useFormValidation(props, validationState, ref);
|
|
146
|
+
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
// This works around a React/Chrome bug that prevents textarea elements from validating when controlled.
|
|
149
|
+
// We prevent React from updating defaultValue (i.e. children) of textarea when `value` changes,
|
|
150
|
+
// which causes Chrome to skip validation. Only updating `value` is ok in our case since our
|
|
151
|
+
// textareas are always controlled. React is planning on removing this synchronization in a
|
|
152
|
+
// future major version.
|
|
153
|
+
// https://github.com/facebook/react/issues/19474
|
|
154
|
+
// https://github.com/facebook/react/issues/11896
|
|
155
|
+
if (ref.current instanceof getOwnerWindow(ref.current).HTMLTextAreaElement) {
|
|
156
|
+
let input = ref.current;
|
|
157
|
+
Object.defineProperty(input, 'defaultValue', {
|
|
158
|
+
get: () => input.value,
|
|
159
|
+
set: () => {},
|
|
160
|
+
configurable: true
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}, [ref]);
|
|
130
164
|
|
|
131
165
|
return {
|
|
132
166
|
labelProps,
|
|
@@ -136,16 +170,17 @@ export function useTextField<T extends TextFieldIntrinsicElements = DefaultEleme
|
|
|
136
170
|
{
|
|
137
171
|
disabled: isDisabled,
|
|
138
172
|
readOnly: isReadOnly,
|
|
139
|
-
|
|
140
|
-
'aria-
|
|
173
|
+
required: isRequired && validationBehavior === 'native',
|
|
174
|
+
'aria-required': (isRequired && validationBehavior === 'aria') || undefined,
|
|
175
|
+
'aria-invalid': isInvalid || undefined,
|
|
141
176
|
'aria-errormessage': props['aria-errormessage'],
|
|
142
177
|
'aria-activedescendant': props['aria-activedescendant'],
|
|
143
178
|
'aria-autocomplete': props['aria-autocomplete'],
|
|
144
179
|
'aria-haspopup': props['aria-haspopup'],
|
|
145
|
-
value
|
|
146
|
-
|
|
147
|
-
onChange: (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.value),
|
|
180
|
+
value,
|
|
181
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),
|
|
148
182
|
autoComplete: props.autoComplete,
|
|
183
|
+
autoCapitalize: props.autoCapitalize,
|
|
149
184
|
maxLength: props.maxLength,
|
|
150
185
|
minLength: props.minLength,
|
|
151
186
|
name: props.name,
|
|
@@ -173,6 +208,9 @@ export function useTextField<T extends TextFieldIntrinsicElements = DefaultEleme
|
|
|
173
208
|
}
|
|
174
209
|
),
|
|
175
210
|
descriptionProps,
|
|
176
|
-
errorMessageProps
|
|
211
|
+
errorMessageProps,
|
|
212
|
+
isInvalid,
|
|
213
|
+
validationErrors,
|
|
214
|
+
validationDetails
|
|
177
215
|
};
|
|
178
216
|
}
|