@react-aria/textfield 3.3.1 → 3.5.2

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/module.js CHANGED
@@ -1,211 +1,189 @@
1
- import { useEffect, useRef } from "react";
2
- import { useLabel } from "@react-aria/label";
3
- import { useFocusable } from "@react-aria/focus";
4
- import { filterDOMProps, mergeProps } from "@react-aria/utils";
5
- import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
1
+ import {filterDOMProps as $aywJT$filterDOMProps, mergeProps as $aywJT$mergeProps} from "@react-aria/utils";
2
+ import {useField as $aywJT$useField} from "@react-aria/label";
3
+ import {useFocusable as $aywJT$useFocusable} from "@react-aria/focus";
4
+ import {useRef as $aywJT$useRef, useEffect as $aywJT$useEffect} from "react";
6
5
 
7
- /**
8
- * Provides the behavior and accessibility implementation for a text field.
9
- * @param props - Props for the text field.
10
- * @param ref - Ref to the HTML input or textarea element.
11
- */
12
- export function useTextField(props, ref) {
13
- let {
14
- inputElementType = 'input',
15
- isDisabled = false,
16
- isRequired = false,
17
- isReadOnly = false,
18
- validationState,
19
- type = 'text',
20
- onChange: _onChange = () => {}
21
- } = props;
22
- let {
23
- focusableProps
24
- } = useFocusable(props, ref);
25
- let {
26
- labelProps,
27
- fieldProps
28
- } = useLabel(props);
29
- let domProps = filterDOMProps(props, {
30
- labelable: true
31
- });
32
- const inputOnlyProps = {
33
- type,
34
- pattern: props.pattern
35
- };
36
- return {
37
- labelProps,
38
- inputProps: mergeProps(domProps, inputElementType === 'input' && inputOnlyProps, _babelRuntimeHelpersEsmExtends({
39
- disabled: isDisabled,
40
- readOnly: isReadOnly,
41
- 'aria-required': isRequired || undefined,
42
- 'aria-invalid': validationState === 'invalid' || undefined,
43
- 'aria-errormessage': props['aria-errormessage'],
44
- 'aria-activedescendant': props['aria-activedescendant'],
45
- 'aria-autocomplete': props['aria-autocomplete'],
46
- 'aria-haspopup': props['aria-haspopup'],
47
- value: props.value,
48
- defaultValue: props.value ? undefined : props.defaultValue,
49
- onChange: e => _onChange(e.target.value),
50
- autoComplete: props.autoComplete,
51
- maxLength: props.maxLength,
52
- minLength: props.minLength,
53
- name: props.name,
54
- placeholder: props.placeholder,
55
- inputMode: props.inputMode,
56
- // Clipboard events
57
- onCopy: props.onCopy,
58
- onCut: props.onCut,
59
- onPaste: props.onPaste,
60
- // Composition events
61
- onCompositionEnd: props.onCompositionEnd,
62
- onCompositionStart: props.onCompositionStart,
63
- onCompositionUpdate: props.onCompositionUpdate,
64
- // Selection events
65
- onSelect: props.onSelect,
66
- // Input events
67
- onBeforeInput: props.onBeforeInput,
68
- onInput: props.onInput
69
- }, focusableProps, fieldProps))
70
- };
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
71
8
  }
9
+ var $13fe50aacf882d03$exports = {};
72
10
 
73
- function $c7e32867b2abc7e2d776d5c060056cb7$var$supportsNativeBeforeInputEvent() {
74
- return typeof window !== 'undefined' && window.InputEvent && // @ts-ignore
75
- typeof InputEvent.prototype.getTargetRanges === 'function';
76
- }
77
-
78
- export function useFormattedTextField(props, state, inputRef) {
79
- let stateRef = useRef(state);
80
- stateRef.current = state; // All browsers implement the 'beforeinput' event natively except Firefox
81
- // (currently behind a flag as of Firefox 84). React's polyfill does not
82
- // run in all cases that the native event fires, e.g. when deleting text.
83
- // Use the native event if available so that we can prevent invalid deletions.
84
- // We do not attempt to polyfill this in Firefox since it would be very complicated,
85
- // the benefit of doing so is fairly minor, and it's going to be natively supported soon.
86
-
87
- useEffect(() => {
88
- if (!$c7e32867b2abc7e2d776d5c060056cb7$var$supportsNativeBeforeInputEvent()) {
89
- return;
90
- }
91
-
92
- let input = inputRef.current;
93
-
94
- let onBeforeInput = e => {
95
- let state = stateRef.current; // Compute the next value of the input if the event is allowed to proceed.
96
- // See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
11
+ $parcel$export($13fe50aacf882d03$exports, "useTextField", () => $13fe50aacf882d03$export$712718f7aec83d5);
97
12
 
98
- let nextValue;
99
13
 
100
- switch (e.inputType) {
101
- case 'historyUndo':
102
- case 'historyRedo':
103
- // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,
104
- // because presumably the input would have already been validated previously.
105
- return;
106
14
 
107
- case 'deleteContent':
108
- case 'deleteByCut':
109
- case 'deleteByDrag':
110
- nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
111
- break;
112
-
113
- case 'deleteContentForward':
114
- // This is potentially incorrect, since the browser may actually delete more than a single UTF-16
115
- // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters
116
- // or code points may be deleted. However, in our currently supported locales, there are no such cases.
117
- // If we support additional locales in the future, this may need to change.
118
- nextValue = input.selectionEnd === input.selectionStart ? input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd + 1) : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
119
- break;
120
-
121
- case 'deleteContentBackward':
122
- nextValue = input.selectionEnd === input.selectionStart ? input.value.slice(0, input.selectionStart - 1) + input.value.slice(input.selectionStart) : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
123
- break;
15
+ function $13fe50aacf882d03$export$712718f7aec83d5(props, ref) {
16
+ let { inputElementType: inputElementType = 'input' , isDisabled: isDisabled = false , isRequired: isRequired = false , isReadOnly: isReadOnly = false , validationState: validationState , type: type = 'text' , onChange: onChange = ()=>{
17
+ } } = props;
18
+ let { focusableProps: focusableProps } = $aywJT$useFocusable(props, ref);
19
+ let { labelProps: labelProps , fieldProps: fieldProps , descriptionProps: descriptionProps , errorMessageProps: errorMessageProps } = $aywJT$useField(props);
20
+ let domProps = $aywJT$filterDOMProps(props, {
21
+ labelable: true
22
+ });
23
+ const inputOnlyProps = {
24
+ type: type,
25
+ pattern: props.pattern
26
+ };
27
+ return {
28
+ labelProps: labelProps,
29
+ inputProps: $aywJT$mergeProps(domProps, inputElementType === 'input' && inputOnlyProps, {
30
+ disabled: isDisabled,
31
+ readOnly: isReadOnly,
32
+ 'aria-required': isRequired || undefined,
33
+ 'aria-invalid': validationState === 'invalid' || undefined,
34
+ 'aria-errormessage': props['aria-errormessage'],
35
+ 'aria-activedescendant': props['aria-activedescendant'],
36
+ 'aria-autocomplete': props['aria-autocomplete'],
37
+ 'aria-haspopup': props['aria-haspopup'],
38
+ value: props.value,
39
+ defaultValue: props.value ? undefined : props.defaultValue,
40
+ onChange: (e)=>onChange(e.target.value)
41
+ ,
42
+ autoComplete: props.autoComplete,
43
+ maxLength: props.maxLength,
44
+ minLength: props.minLength,
45
+ name: props.name,
46
+ placeholder: props.placeholder,
47
+ inputMode: props.inputMode,
48
+ // Clipboard events
49
+ onCopy: props.onCopy,
50
+ onCut: props.onCut,
51
+ onPaste: props.onPaste,
52
+ // Composition events
53
+ onCompositionEnd: props.onCompositionEnd,
54
+ onCompositionStart: props.onCompositionStart,
55
+ onCompositionUpdate: props.onCompositionUpdate,
56
+ // Selection events
57
+ onSelect: props.onSelect,
58
+ // Input events
59
+ onBeforeInput: props.onBeforeInput,
60
+ onInput: props.onInput,
61
+ ...focusableProps,
62
+ ...fieldProps
63
+ }),
64
+ descriptionProps: descriptionProps,
65
+ errorMessageProps: errorMessageProps
66
+ };
67
+ }
124
68
 
125
- case 'deleteSoftLineBackward':
126
- case 'deleteHardLineBackward':
127
- nextValue = input.value.slice(input.selectionStart);
128
- break;
129
69
 
130
- default:
131
- if (e.data != null) {
132
- nextValue = input.value.slice(0, input.selectionStart) + e.data + input.value.slice(input.selectionEnd);
133
- }
70
+ var $58c0262056d833d5$exports = {};
134
71
 
135
- break;
136
- } // If we did not compute a value, or the new value is invalid, prevent the event
137
- // so that the browser does not update the input text, move the selection, or add to
138
- // the undo/redo stack.
72
+ $parcel$export($58c0262056d833d5$exports, "useFormattedTextField", () => $58c0262056d833d5$export$4f384c9210e583c3);
139
73
 
140
74
 
141
- if (nextValue == null || !state.validate(nextValue)) {
142
- e.preventDefault();
143
- }
144
- };
145
75
 
146
- input.addEventListener('beforeinput', onBeforeInput, false);
147
- return () => {
148
- input.removeEventListener('beforeinput', onBeforeInput, false);
76
+ function $58c0262056d833d5$var$supportsNativeBeforeInputEvent() {
77
+ return typeof window !== 'undefined' && window.InputEvent && // @ts-ignore
78
+ typeof InputEvent.prototype.getTargetRanges === 'function';
79
+ }
80
+ function $58c0262056d833d5$export$4f384c9210e583c3(props, state1, inputRef) {
81
+ let stateRef = $aywJT$useRef(state1);
82
+ stateRef.current = state1;
83
+ // All browsers implement the 'beforeinput' event natively except Firefox
84
+ // (currently behind a flag as of Firefox 84). React's polyfill does not
85
+ // run in all cases that the native event fires, e.g. when deleting text.
86
+ // Use the native event if available so that we can prevent invalid deletions.
87
+ // We do not attempt to polyfill this in Firefox since it would be very complicated,
88
+ // the benefit of doing so is fairly minor, and it's going to be natively supported soon.
89
+ $aywJT$useEffect(()=>{
90
+ if (!$58c0262056d833d5$var$supportsNativeBeforeInputEvent()) return;
91
+ let input = inputRef.current;
92
+ let onBeforeInput = (e)=>{
93
+ let state = stateRef.current;
94
+ // Compute the next value of the input if the event is allowed to proceed.
95
+ // See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
96
+ let nextValue;
97
+ switch(e.inputType){
98
+ case 'historyUndo':
99
+ case 'historyRedo':
100
+ // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,
101
+ // because presumably the input would have already been validated previously.
102
+ return;
103
+ case 'deleteContent':
104
+ case 'deleteByCut':
105
+ case 'deleteByDrag':
106
+ nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
107
+ break;
108
+ case 'deleteContentForward':
109
+ // This is potentially incorrect, since the browser may actually delete more than a single UTF-16
110
+ // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters
111
+ // or code points may be deleted. However, in our currently supported locales, there are no such cases.
112
+ // If we support additional locales in the future, this may need to change.
113
+ nextValue = input.selectionEnd === input.selectionStart ? input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd + 1) : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
114
+ break;
115
+ case 'deleteContentBackward':
116
+ nextValue = input.selectionEnd === input.selectionStart ? input.value.slice(0, input.selectionStart - 1) + input.value.slice(input.selectionStart) : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
117
+ break;
118
+ case 'deleteSoftLineBackward':
119
+ case 'deleteHardLineBackward':
120
+ nextValue = input.value.slice(input.selectionStart);
121
+ break;
122
+ default:
123
+ if (e.data != null) nextValue = input.value.slice(0, input.selectionStart) + e.data + input.value.slice(input.selectionEnd);
124
+ break;
125
+ }
126
+ // If we did not compute a value, or the new value is invalid, prevent the event
127
+ // so that the browser does not update the input text, move the selection, or add to
128
+ // the undo/redo stack.
129
+ if (nextValue == null || !state.validate(nextValue)) e.preventDefault();
130
+ };
131
+ input.addEventListener('beforeinput', onBeforeInput, false);
132
+ return ()=>{
133
+ input.removeEventListener('beforeinput', onBeforeInput, false);
134
+ };
135
+ }, [
136
+ inputRef,
137
+ stateRef
138
+ ]);
139
+ let onBeforeInput1 = !$58c0262056d833d5$var$supportsNativeBeforeInputEvent() ? (e)=>{
140
+ let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
141
+ if (!state1.validate(nextValue)) e.preventDefault();
142
+ } : null;
143
+ let { labelProps: labelProps , inputProps: textFieldProps , descriptionProps: descriptionProps , errorMessageProps: errorMessageProps } = $13fe50aacf882d03$export$712718f7aec83d5(props, inputRef);
144
+ let compositionStartState = $aywJT$useRef(null);
145
+ return {
146
+ inputProps: $aywJT$mergeProps(textFieldProps, {
147
+ onBeforeInput: onBeforeInput1,
148
+ onCompositionStart () {
149
+ // Chrome does not implement Input Events Level 2, which specifies the insertFromComposition
150
+ // and deleteByComposition inputType values for the beforeinput event. These are meant to occur
151
+ // at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are
152
+ // cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,
153
+ // nor would we want to cancel them because the input from the user is incomplete at that point.
154
+ // In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel
155
+ // the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either
156
+ // don't support Input Events Level 2, or beforeinput at all, we store the state of the input when
157
+ // the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.
158
+ // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
159
+ // are implemented, there is no other way to prevent composed input.
160
+ // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
161
+ let { value: value , selectionStart: selectionStart , selectionEnd: selectionEnd } = inputRef.current;
162
+ compositionStartState.current = {
163
+ value: value,
164
+ selectionStart: selectionStart,
165
+ selectionEnd: selectionEnd
166
+ };
167
+ },
168
+ onCompositionEnd () {
169
+ if (!state1.validate(inputRef.current.value)) {
170
+ // Restore the input value in the DOM immediately so we can synchronously update the selection position.
171
+ // But also update the value in React state as well so it is correct for future updates.
172
+ let { value: value , selectionStart: selectionStart , selectionEnd: selectionEnd } = compositionStartState.current;
173
+ inputRef.current.value = value;
174
+ inputRef.current.setSelectionRange(selectionStart, selectionEnd);
175
+ state1.setInputValue(value);
176
+ }
177
+ }
178
+ }),
179
+ labelProps: labelProps,
180
+ descriptionProps: descriptionProps,
181
+ errorMessageProps: errorMessageProps
149
182
  };
150
- }, [inputRef, stateRef]);
151
- let onBeforeInput = !$c7e32867b2abc7e2d776d5c060056cb7$var$supportsNativeBeforeInputEvent() ? e => {
152
- let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
183
+ }
153
184
 
154
- if (!state.validate(nextValue)) {
155
- e.preventDefault();
156
- }
157
- } : null;
158
- let {
159
- labelProps,
160
- inputProps: textFieldProps
161
- } = useTextField(props, inputRef);
162
- let compositionStartState = useRef(null);
163
- return {
164
- inputProps: mergeProps(textFieldProps, {
165
- onBeforeInput,
166
185
 
167
- onCompositionStart() {
168
- // Chrome does not implement Input Events Level 2, which specifies the insertFromComposition
169
- // and deleteByComposition inputType values for the beforeinput event. These are meant to occur
170
- // at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are
171
- // cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,
172
- // nor would we want to cancel them because the input from the user is incomplete at that point.
173
- // In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel
174
- // the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either
175
- // don't support Input Events Level 2, or beforeinput at all, we store the state of the input when
176
- // the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.
177
- // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
178
- // are implemented, there is no other way to prevent composed input.
179
- // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
180
- let {
181
- value,
182
- selectionStart,
183
- selectionEnd
184
- } = inputRef.current;
185
- compositionStartState.current = {
186
- value,
187
- selectionStart,
188
- selectionEnd
189
- };
190
- },
191
186
 
192
- onCompositionEnd() {
193
- if (!state.validate(inputRef.current.value)) {
194
- // Restore the input value in the DOM immediately so we can synchronously update the selection position.
195
- // But also update the value in React state as well so it is correct for future updates.
196
- let {
197
- value,
198
- selectionStart,
199
- selectionEnd
200
- } = compositionStartState.current;
201
- inputRef.current.value = value;
202
- inputRef.current.setSelectionRange(selectionStart, selectionEnd);
203
- state.setInputValue(value);
204
- }
205
- }
206
187
 
207
- }),
208
- labelProps
209
- };
210
- }
188
+ export {$13fe50aacf882d03$export$712718f7aec83d5 as useTextField, $58c0262056d833d5$export$4f384c9210e583c3 as useFormattedTextField};
211
189
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAoCA;;;;;OAKO,SAASA,YAAT,CACLC,KADK,EAELC,GAFK,EAGU;AACf,MAAI;AACFC,IAAAA,gBAAgB,GAAG,OADjB;AAEFC,IAAAA,UAAU,GA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Q,CAACG,OAAT,CAAiBe,iBAAjB,CAAmCT,cAAnC,EAAmDC,YAAnD;AACAX,UAAAA,KAAK,CAACoB,aAAN,CAAoB7C,KAApB;AACD;AACF;;AA3BH,KAFoB,CADjB;AAiCLb,IAAAA;AAjCK,GAAP;AAmCD","sources":["./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 */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {ChangeEvent, InputHTMLAttributes, LabelHTMLAttributes, RefObject, TextareaHTMLAttributes} from 'react';\nimport {ElementType} from 'react';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useFocusable} from '@react-aria/focus';\nimport {useLabel} from '@react-aria/label';\n\nexport interface TextFieldAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement> | TextareaHTMLAttributes<HTMLTextAreaElement>,\n /** Props for the text field's visible label element (if any). */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>\n}\n\ninterface AriaTextFieldOptions 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?: ElementType\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(\n props: AriaTextFieldOptions,\n ref: RefObject<HTMLInputElement | HTMLTextAreaElement>\n): TextFieldAria {\n let {\n inputElementType = 'input',\n isDisabled = false,\n isRequired = false,\n isReadOnly = false,\n validationState,\n type = 'text',\n onChange = () => {}\n } = props;\n let {focusableProps} = useFocusable(props, ref);\n let {labelProps, fieldProps} = useLabel(props);\n let domProps = filterDOMProps(props, {labelable: true});\n\n const inputOnlyProps = {\n type,\n pattern: props.pattern\n };\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': 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 };\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} 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\n let stateRef = useRef(state);\n stateRef.current = state;\n\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 useEffect(() => {\n if (!supportsNativeBeforeInputEvent()) {\n return;\n }\n\n let input = inputRef.current;\n\n let onBeforeInput = (e: InputEvent) => {\n let state = stateRef.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 input.addEventListener('beforeinput', onBeforeInput, false);\n return () => {\n input.removeEventListener('beforeinput', onBeforeInput, false);\n };\n }, [inputRef, stateRef]);\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} = 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 };\n}\n"],"names":["useTextField","props","ref","inputElementType","isDisabled","isRequired","isReadOnly","validationState","type","onChange","focusableProps","useFocusable","labelProps","fieldProps","useLabel","domProps","filterDOMProps","labelable","inputOnlyProps","pattern","inputProps","mergeProps","disabled","readOnly","undefined","value","defaultValue","e","target","autoComplete","maxLength","minLength","name","placeholder","inputMode","onCopy","onCut","onPaste","onCompositionEnd","onCompositionStart","onCompositionUpdate","onSelect","onBeforeInput","onInput","supportsNativeBeforeInputEvent","window","InputEvent","prototype","getTargetRanges","useFormattedTextField","state","inputRef","stateRef","useRef","current","useEffect","input","nextValue","inputType","slice","selectionStart","selectionEnd","data","validate","preventDefault","addEventListener","removeEventListener","textFieldProps","compositionStartState","setSelectionRange","setInputValue"],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;SCsGgB,wCAAY,CAC1B,KAA8B,EAC9B,GAA0B,EACR,CAAC;IACnB,GAAG,CAAC,CAAC,mBACH,gBAAgB,GAAG,CAAO,qBAC1B,UAAU,GAAG,KAAK,eAClB,UAAU,GAAG,KAAK,eAClB,UAAU,GAAG,KAAK,oBAClB,eAAe,SACf,IAAI,GAAG,CAAM,kBACb,QAAQ,OAAS,CAAC;IAAA,CAAC,EACrB,CAAC,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,iBAAE,YAAY,EAAA,CAAC,GAAG,qBAAqB,CAAC,OAAO;oBACzE,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK;oBAC9B,QAAQ,CAAC,OAAO,CAAC,iBAAiB,CAAC,cAAc,EAAE,YAAY;oBAC/D,MAAK,CAAC,aAAa,CAAC,KAAK;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC;oBAEH,UAAU;0BACV,gBAAgB;2BAChB,iBAAiB;IACnB,CAAC;AACH,CAAC;;","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 */\n\nexport * from './useTextField';\nexport * from './useFormattedTextField';\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 {filterDOMProps, mergeProps} 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\ninterface 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: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the text field's description element, if any. */\n descriptionProps: HTMLAttributes<HTMLElement>,\n /** Props for the text field's error message element, if any. */\n errorMessageProps: HTMLAttributes<HTMLElement>\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 type = 'text',\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 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': 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} 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\n let stateRef = useRef(state);\n stateRef.current = state;\n\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 useEffect(() => {\n if (!supportsNativeBeforeInputEvent()) {\n return;\n }\n\n let input = inputRef.current;\n\n let onBeforeInput = (e: InputEvent) => {\n let state = stateRef.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 input.addEventListener('beforeinput', onBeforeInput, false);\n return () => {\n input.removeEventListener('beforeinput', onBeforeInput, false);\n };\n }, [inputRef, stateRef]);\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"}
package/dist/types.d.ts CHANGED
@@ -1,26 +1,73 @@
1
1
  import { AriaTextFieldProps } from "@react-types/textfield";
2
- import { InputHTMLAttributes, LabelHTMLAttributes, RefObject, TextareaHTMLAttributes, ElementType } from "react";
3
- export interface TextFieldAria {
4
- /** Props for the input element. */
5
- inputProps: InputHTMLAttributes<HTMLInputElement> | TextareaHTMLAttributes<HTMLTextAreaElement>;
6
- /** Props for the text field's visible label element (if any). */
7
- labelProps: LabelHTMLAttributes<HTMLLabelElement>;
8
- }
9
- interface AriaTextFieldOptions extends AriaTextFieldProps {
2
+ import { DOMFactory, HTMLAttributes, LabelHTMLAttributes, ReactDOM, RefObject } from "react";
3
+ /**
4
+ * A map of HTML element names and their interface types.
5
+ * For example `'a'` -> `HTMLAnchorElement`.
6
+ */
7
+ type IntrinsicHTMLElements = {
8
+ [K in keyof IntrinsicHTMLAttributes]: IntrinsicHTMLAttributes[K] extends HTMLAttributes<infer T> ? T : never;
9
+ };
10
+ /**
11
+ * A map of HTML element names and their attribute interface types.
12
+ * For example `'a'` -> `AnchorHTMLAttributes<HTMLAnchorElement>`.
13
+ */
14
+ type IntrinsicHTMLAttributes = {
15
+ [K in keyof ReactDOM]: ReactDOM[K] extends DOMFactory<infer T, any> ? T : never;
16
+ };
17
+ type DefaultElementType = 'input';
18
+ /**
19
+ * The intrinsic HTML element names that `useTextField` supports; e.g. `input`,
20
+ * `textarea`.
21
+ */
22
+ type TextFieldIntrinsicElements = keyof Pick<IntrinsicHTMLElements, 'input' | 'textarea'>;
23
+ /**
24
+ * The HTML element interfaces that `useTextField` supports based on what is
25
+ * defined for `TextFieldIntrinsicElements`; e.g. `HTMLInputElement`,
26
+ * `HTMLTextAreaElement`.
27
+ */
28
+ type TextFieldHTMLElementType = Pick<IntrinsicHTMLElements, TextFieldIntrinsicElements>;
29
+ /**
30
+ * The HTML attributes interfaces that `useTextField` supports based on what
31
+ * is defined for `TextFieldIntrinsicElements`; e.g. `InputHTMLAttributes`,
32
+ * `TextareaHTMLAttributes`.
33
+ */
34
+ type TextFieldHTMLAttributesType = Pick<IntrinsicHTMLAttributes, TextFieldIntrinsicElements>;
35
+ /**
36
+ * The type of `inputProps` returned by `useTextField`; e.g. `InputHTMLAttributes`,
37
+ * `TextareaHTMLAttributes`.
38
+ */
39
+ type TextFieldInputProps<T extends TextFieldIntrinsicElements> = TextFieldHTMLAttributesType[T];
40
+ interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps {
10
41
  /**
11
42
  * The HTML element used to render the input, e.g. 'input', or 'textarea'.
12
43
  * It determines whether certain HTML attributes will be included in `inputProps`.
13
44
  * For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).
14
45
  * @default 'input'
15
46
  */
16
- inputElementType?: ElementType;
47
+ inputElementType?: T;
48
+ }
49
+ /**
50
+ * The type of `ref` object that can be passed to `useTextField` based on the given
51
+ * intrinsic HTML element name; e.g.`RefObject<HTMLInputElement>`,
52
+ * `RefObject<HTMLTextAreaElement>`.
53
+ */
54
+ type TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T]>;
55
+ export interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> {
56
+ /** Props for the input element. */
57
+ inputProps: TextFieldInputProps<T>;
58
+ /** Props for the text field's visible label element, if any. */
59
+ labelProps: LabelHTMLAttributes<HTMLLabelElement>;
60
+ /** Props for the text field's description element, if any. */
61
+ descriptionProps: HTMLAttributes<HTMLElement>;
62
+ /** Props for the text field's error message element, if any. */
63
+ errorMessageProps: HTMLAttributes<HTMLElement>;
17
64
  }
18
65
  /**
19
66
  * Provides the behavior and accessibility implementation for a text field.
20
67
  * @param props - Props for the text field.
21
68
  * @param ref - Ref to the HTML input or textarea element.
22
69
  */
23
- export function useTextField(props: AriaTextFieldOptions, ref: RefObject<HTMLInputElement | HTMLTextAreaElement>): TextFieldAria;
70
+ export function useTextField<T extends TextFieldIntrinsicElements = DefaultElementType>(props: AriaTextFieldOptions<T>, ref: TextFieldRefObject<T>): TextFieldAria<T>;
24
71
  interface FormattedTextFieldState {
25
72
  validate: (val: string) => boolean;
26
73
  setInputValue: (val: string) => void;
@@ -1 +1 @@
1
- {"mappings":"A;A;AAmBA;IACE,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,GAAG,uBAAuB,mBAAmB,CAAC,CAAC;IAChG,iEAAiE;IACjE,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAA;CAClD;AAED,8BAA+B,SAAQ,kBAAkB;IACvD;A;A;A;A;OAKG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAA;CAC/B;AAED;A;A;A;GAIG;AACH,6BACE,KAAK,EAAE,oBAAoB,EAC3B,GAAG,EAAE,UAAU,gBAAgB,GAAG,mBAAmB,CAAC,GACrD,aAAa,CAgEf;AC3FD;IACE,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACnC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CACrC;AAUD,sCAAsC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,uBAAuB,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,aAAa,CAgIrJ","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"],"sourcesContent":[null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AAyBA;;;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,CA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,EAAE,UAAU,gBAAgB,CAAC,GAAG,aAAa,CAkIrJ","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 */\n\nexport * from './useTextField';\nexport * from './useFormattedTextField';\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.1",
3
+ "version": "3.5.2",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,11 +18,11 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-aria/focus": "^3.4.1",
22
- "@react-aria/label": "^3.1.3",
23
- "@react-aria/utils": "^3.8.2",
24
- "@react-types/shared": "^3.8.0",
25
- "@react-types/textfield": "^3.2.3"
21
+ "@react-aria/focus": "^3.5.2",
22
+ "@react-aria/label": "^3.2.3",
23
+ "@react-aria/utils": "^3.11.2",
24
+ "@react-types/shared": "^3.11.1",
25
+ "@react-types/textfield": "^3.3.2"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "^16.8.0 || ^17.0.0-rc.1"
@@ -30,5 +30,5 @@
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "9204e1b8cb61dac767e91087fb16203611dc67c5"
33
+ "gitHead": "404d41859b7d6f56201d7fc01bd9f22ae3512937"
34
34
  }
@@ -118,7 +118,7 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
118
118
  }
119
119
  : null;
120
120
 
121
- let {labelProps, inputProps: textFieldProps} = useTextField(props, inputRef);
121
+ let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps} = useTextField(props, inputRef);
122
122
 
123
123
  let compositionStartState = useRef(null);
124
124
  return {
@@ -154,6 +154,8 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
154
154
  }
155
155
  }
156
156
  ),
157
- labelProps
157
+ labelProps,
158
+ descriptionProps,
159
+ errorMessageProps
158
160
  };
159
161
  }