@react-aria/textfield 3.14.10 → 3.16.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/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useFormattedTextField.main.js +5 -5
- package/dist/useFormattedTextField.main.js.map +1 -1
- package/dist/useFormattedTextField.mjs +5 -5
- package/dist/useFormattedTextField.module.js +5 -5
- package/dist/useFormattedTextField.module.js.map +1 -1
- package/dist/useTextField.main.js +3 -0
- package/dist/useTextField.main.js.map +1 -1
- package/dist/useTextField.mjs +3 -0
- package/dist/useTextField.module.js +3 -0
- package/dist/useTextField.module.js.map +1 -1
- package/package.json +12 -11
- package/src/useFormattedTextField.ts +17 -15
- package/src/useTextField.ts +6 -3
package/dist/types.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ type TextFieldHTMLAttributesType = Pick<IntrinsicHTMLAttributes, TextFieldIntrin
|
|
|
36
36
|
* `TextareaHTMLAttributes`.
|
|
37
37
|
*/
|
|
38
38
|
type TextFieldInputProps<T extends TextFieldIntrinsicElements> = TextFieldHTMLAttributesType[T];
|
|
39
|
-
export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps {
|
|
39
|
+
export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps<TextFieldHTMLElementType[T]> {
|
|
40
40
|
/**
|
|
41
41
|
* The HTML element used to render the input, e.g. 'input', or 'textarea'.
|
|
42
42
|
* It determines whether certain HTML attributes will be included in `inputProps`.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AA6BA;;;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,I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AG,WAAW,GAAG,OAAO,GAAG,YAAY,CAAA;CAC9E;AAED;;;;GAIG;AACH,wBAAwB,CAAC,SAAS,0BAA0B,IAAI,UAAU,wBAAwB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AAE9G,+BAA+B,CAAC,SAAS,0BAA0B,GAAG,kBAAkB,CAAE,SAAQ,gBAAgB;IAChH,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,CAAC,CAAC,CAAC;IACnC,gEAAgE;IAChE,UAAU,EAAE,aAAa,GAAG,oBAAoB,gBAAgB,CAAC,CAAC;IAClE,8DAA8D;IAC9D,gBAAgB,EAAE,aAAa,CAAC;IAChC,gEAAgE;IAChE,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;GAIG;AACH,6BAA6B,CAAC,SAAS,0BAA0B,GAAG,kBAAkB,EACpF,KAAK,EAAE,qBAAqB,CAAC,CAAC,EAC9B,GAAG,EAAE,mBAAmB,CAAC,CAAC,GACzB,cAAc,CAAC,CAAC,CAuGlB;ACrMD;IACE,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACnC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CACrC;AASD,sCAAsC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,uBAAuB,EAAE,QAAQ,EAAE,YAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,aAAa,CAoI5J;ACnJD,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"}
|
|
@@ -22,8 +22,7 @@ $parcel$export(module.exports, "useFormattedTextField", () => $56b68c3dab9bf16c$
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
function $56b68c3dab9bf16c$var$supportsNativeBeforeInputEvent() {
|
|
25
|
-
return typeof window !== 'undefined' && window.InputEvent &&
|
|
26
|
-
typeof InputEvent.prototype.getTargetRanges === 'function';
|
|
25
|
+
return typeof window !== 'undefined' && window.InputEvent && typeof InputEvent.prototype.getTargetRanges === 'function';
|
|
27
26
|
}
|
|
28
27
|
function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
|
|
29
28
|
// All browsers implement the 'beforeinput' event natively except Firefox
|
|
@@ -34,9 +33,10 @@ function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
34
33
|
// the benefit of doing so is fairly minor, and it's going to be natively supported soon.
|
|
35
34
|
let onBeforeInputFallback = (0, $6PuoT$reactariautils.useEffectEvent)((e)=>{
|
|
36
35
|
let input = inputRef.current;
|
|
36
|
+
if (!input) return;
|
|
37
37
|
// Compute the next value of the input if the event is allowed to proceed.
|
|
38
38
|
// See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
|
|
39
|
-
let nextValue;
|
|
39
|
+
let nextValue = null;
|
|
40
40
|
switch(e.inputType){
|
|
41
41
|
case 'historyUndo':
|
|
42
42
|
case 'historyRedo':
|
|
@@ -75,7 +75,7 @@ function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
75
75
|
if (nextValue == null || !state.validate(nextValue)) e.preventDefault();
|
|
76
76
|
});
|
|
77
77
|
(0, $6PuoT$react.useEffect)(()=>{
|
|
78
|
-
if (!$56b68c3dab9bf16c$var$supportsNativeBeforeInputEvent()) return;
|
|
78
|
+
if (!$56b68c3dab9bf16c$var$supportsNativeBeforeInputEvent() || !inputRef.current) return;
|
|
79
79
|
let input = inputRef.current;
|
|
80
80
|
input.addEventListener('beforeinput', onBeforeInputFallback, false);
|
|
81
81
|
return ()=>{
|
|
@@ -115,7 +115,7 @@ function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
115
115
|
};
|
|
116
116
|
},
|
|
117
117
|
onCompositionEnd () {
|
|
118
|
-
if (!state.validate(inputRef.current.value)) {
|
|
118
|
+
if (inputRef.current && !state.validate(inputRef.current.value)) {
|
|
119
119
|
// Restore the input value in the DOM immediately so we can synchronously update the selection position.
|
|
120
120
|
// But also update the value in React state as well so it is correct for future updates.
|
|
121
121
|
let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = compositionStartState.current;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAcD,SAAS;IACP,OAAO,OAAO,WAAW,eACvB,OAAO,UAAU,IACjB,aAAa;IACb,OAAO,WAAW,SAAS,CAAC,eAAe,KAAK;AACpD;AAEO,SAAS,0CAAsB,KAAyB,EAAE,KAA8B,EAAE,QAA4C;IAC3I,yEAAyE;IACzE,wEAAwE;IACxE,yEAAyE;IACzE,8EAA8E;IAC9E,oFAAoF;IACpF,yFAAyF;IACzF,IAAI,wBAAwB,CAAA,GAAA,oCAAa,EAAE,CAAC;QAC1C,IAAI,QAAQ,SAAS,OAAO;QAE5B,0EAA0E;QAC1E,4GAA4G;QAC5G,IAAI;QACJ,OA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AAE,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/useFormattedTextField.ts"],"sourcesContent":["/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {RefObject} from '@react-types/shared';\nimport {TextFieldAria, useTextField} from './useTextField';\nimport {useEffect, useRef} from 'react';\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 | null>): TextFieldAria {\n // All browsers implement the 'beforeinput' event natively except Firefox\n // (currently behind a flag as of Firefox 84). React's polyfill does not\n // run in all cases that the native event fires, e.g. when deleting text.\n // Use the native event if available so that we can prevent invalid deletions.\n // We do not attempt to polyfill this in Firefox since it would be very complicated,\n // the benefit of doing so is fairly minor, and it's going to be natively supported soon.\n let onBeforeInputFallback = useEffectEvent((e: InputEvent) => {\n let input = inputRef.current;\n\n // Compute the next value of the input if the event is allowed to proceed.\n // See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.\n let nextValue: string;\n switch (e.inputType) {\n case 'historyUndo':\n case 'historyRedo':\n // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,\n // because presumably the input would have already been validated previously.\n return;\n case 'insertLineBreak':\n // Explicitly allow \"insertLineBreak\" event, to allow onSubmit for \"enter\" key. e.data is null in this case.\n return;\n case 'deleteContent':\n case 'deleteByCut':\n case 'deleteByDrag':\n nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n break;\n case 'deleteContentForward':\n // This is potentially incorrect, since the browser may actually delete more than a single UTF-16\n // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters\n // or code points may be deleted. However, in our currently supported locales, there are no such cases.\n // If we support additional locales in the future, this may need to change.\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd + 1)\n : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n break;\n case 'deleteContentBackward':\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart - 1) + input.value.slice(input.selectionStart)\n : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n break;\n case 'deleteSoftLineBackward':\n case 'deleteHardLineBackward':\n nextValue = input.value.slice(input.selectionStart);\n break;\n default:\n if (e.data != null) {\n nextValue =\n input.value.slice(0, input.selectionStart) +\n e.data +\n input.value.slice(input.selectionEnd);\n }\n break;\n }\n\n // If we did not compute a value, or the new value is invalid, prevent the event\n // so that the browser does not update the input text, move the selection, or add to\n // the undo/redo stack.\n if (nextValue == null || !state.validate(nextValue)) {\n e.preventDefault();\n }\n });\n\n useEffect(() => {\n if (!supportsNativeBeforeInputEvent()) {\n return;\n }\n\n let input = inputRef.current;\n input.addEventListener('beforeinput', onBeforeInputFallback, false);\n return () => {\n input.removeEventListener('beforeinput', onBeforeInputFallback, false);\n };\n }, [inputRef, onBeforeInputFallback]);\n\n let onBeforeInput = !supportsNativeBeforeInputEvent()\n ? e => {\n let nextValue =\n e.target.value.slice(0, e.target.selectionStart) +\n e.data +\n e.target.value.slice(e.target.selectionEnd);\n\n if (!state.validate(nextValue)) {\n e.preventDefault();\n }\n }\n : null;\n\n let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps, ...validation} = useTextField(props, inputRef);\n\n let compositionStartState = useRef(null);\n return {\n inputProps: mergeProps(\n textFieldProps,\n {\n onBeforeInput,\n onCompositionStart() {\n // Chrome does not implement Input Events Level 2, which specifies the insertFromComposition\n // and deleteByComposition inputType values for the beforeinput event. These are meant to occur\n // at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are\n // cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,\n // nor would we want to cancel them because the input from the user is incomplete at that point.\n // In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel\n // the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either\n // don't support Input Events Level 2, or beforeinput at all, we store the state of the input when\n // the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.\n // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition\n // are implemented, there is no other way to prevent composed input.\n // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204\n let {value, selectionStart, selectionEnd} = inputRef.current;\n compositionStartState.current = {value, selectionStart, selectionEnd};\n },\n onCompositionEnd() {\n if (!state.validate(inputRef.current.value)) {\n // Restore the input value in the DOM immediately so we can synchronously update the selection position.\n // But also update the value in React state as well so it is correct for future updates.\n let {value, selectionStart, selectionEnd} = compositionStartState.current;\n inputRef.current.value = value;\n inputRef.current.setSelectionRange(selectionStart, selectionEnd);\n state.setInputValue(value);\n }\n }\n }\n ),\n labelProps,\n descriptionProps,\n errorMessageProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useFormattedTextField.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA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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,SAAS,OAAO,IAAI,CAAC,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC,KAAK,GAAG;oBAC/D,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/useFormattedTextField.ts"],"sourcesContent":["/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {RefObject} from '@react-types/shared';\nimport {TextFieldAria, useTextField} from './useTextField';\nimport {useEffect, useRef} from 'react';\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 typeof InputEvent.prototype.getTargetRanges === 'function';\n}\n\nexport function useFormattedTextField(props: AriaTextFieldProps, state: FormattedTextFieldState, inputRef: RefObject<HTMLInputElement | null>): 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 if (!input) {\n return;\n }\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 | null = null;\n switch (e.inputType) {\n case 'historyUndo':\n case 'historyRedo':\n // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,\n // because presumably the input would have already been validated previously.\n return;\n case 'insertLineBreak':\n // Explicitly allow \"insertLineBreak\" event, to allow onSubmit for \"enter\" key. e.data is null in this case.\n return;\n case 'deleteContent':\n case 'deleteByCut':\n case 'deleteByDrag':\n nextValue = input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);\n break;\n case 'deleteContentForward':\n // This is potentially incorrect, since the browser may actually delete more than a single UTF-16\n // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters\n // or code points may be deleted. However, in our currently supported locales, there are no such cases.\n // If we support additional locales in the future, this may need to change.\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd! + 1)\n : input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);\n break;\n case 'deleteContentBackward':\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart! - 1) + input.value.slice(input.selectionStart!)\n : input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);\n break;\n case 'deleteSoftLineBackward':\n case 'deleteHardLineBackward':\n nextValue = input.value.slice(input.selectionStart!);\n break;\n default:\n if (e.data != null) {\n nextValue =\n input.value.slice(0, input.selectionStart!) +\n e.data +\n input.value.slice(input.selectionEnd!);\n }\n break;\n }\n\n // If we did not compute a value, or the new value is invalid, prevent the event\n // so that the browser does not update the input text, move the selection, or add to\n // the undo/redo stack.\n if (nextValue == null || !state.validate(nextValue)) {\n e.preventDefault();\n }\n });\n\n useEffect(() => {\n if (!supportsNativeBeforeInputEvent() || !inputRef.current) {\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<{value: string, selectionStart: number | null, selectionEnd: number | null} | null>(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 (inputRef.current && !state.validate(inputRef.current.value)) {\n // Restore the input value in the DOM immediately so we can synchronously update the selection position.\n // But also update the value in React state as well so it is correct for future updates.\n let {value, selectionStart, selectionEnd} = compositionStartState.current!;\n inputRef.current.value = value;\n inputRef.current.setSelectionRange(selectionStart, selectionEnd);\n state.setInputValue(value);\n }\n }\n }\n ),\n labelProps,\n descriptionProps,\n errorMessageProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useFormattedTextField.main.js.map"}
|
|
@@ -16,8 +16,7 @@ import {useEffect as $jyGKS$useEffect, useRef as $jyGKS$useRef} from "react";
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
function $d841c8010a73d545$var$supportsNativeBeforeInputEvent() {
|
|
19
|
-
return typeof window !== 'undefined' && window.InputEvent &&
|
|
20
|
-
typeof InputEvent.prototype.getTargetRanges === 'function';
|
|
19
|
+
return typeof window !== 'undefined' && window.InputEvent && typeof InputEvent.prototype.getTargetRanges === 'function';
|
|
21
20
|
}
|
|
22
21
|
function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
23
22
|
// All browsers implement the 'beforeinput' event natively except Firefox
|
|
@@ -28,9 +27,10 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
28
27
|
// the benefit of doing so is fairly minor, and it's going to be natively supported soon.
|
|
29
28
|
let onBeforeInputFallback = (0, $jyGKS$useEffectEvent)((e)=>{
|
|
30
29
|
let input = inputRef.current;
|
|
30
|
+
if (!input) return;
|
|
31
31
|
// Compute the next value of the input if the event is allowed to proceed.
|
|
32
32
|
// See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
|
|
33
|
-
let nextValue;
|
|
33
|
+
let nextValue = null;
|
|
34
34
|
switch(e.inputType){
|
|
35
35
|
case 'historyUndo':
|
|
36
36
|
case 'historyRedo':
|
|
@@ -69,7 +69,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
69
69
|
if (nextValue == null || !state.validate(nextValue)) e.preventDefault();
|
|
70
70
|
});
|
|
71
71
|
(0, $jyGKS$useEffect)(()=>{
|
|
72
|
-
if (!$d841c8010a73d545$var$supportsNativeBeforeInputEvent()) return;
|
|
72
|
+
if (!$d841c8010a73d545$var$supportsNativeBeforeInputEvent() || !inputRef.current) return;
|
|
73
73
|
let input = inputRef.current;
|
|
74
74
|
input.addEventListener('beforeinput', onBeforeInputFallback, false);
|
|
75
75
|
return ()=>{
|
|
@@ -109,7 +109,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
109
109
|
};
|
|
110
110
|
},
|
|
111
111
|
onCompositionEnd () {
|
|
112
|
-
if (!state.validate(inputRef.current.value)) {
|
|
112
|
+
if (inputRef.current && !state.validate(inputRef.current.value)) {
|
|
113
113
|
// Restore the input value in the DOM immediately so we can synchronously update the selection position.
|
|
114
114
|
// But also update the value in React state as well so it is correct for future updates.
|
|
115
115
|
let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = compositionStartState.current;
|
|
@@ -16,8 +16,7 @@ import {useEffect as $jyGKS$useEffect, useRef as $jyGKS$useRef} from "react";
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
function $d841c8010a73d545$var$supportsNativeBeforeInputEvent() {
|
|
19
|
-
return typeof window !== 'undefined' && window.InputEvent &&
|
|
20
|
-
typeof InputEvent.prototype.getTargetRanges === 'function';
|
|
19
|
+
return typeof window !== 'undefined' && window.InputEvent && typeof InputEvent.prototype.getTargetRanges === 'function';
|
|
21
20
|
}
|
|
22
21
|
function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
23
22
|
// All browsers implement the 'beforeinput' event natively except Firefox
|
|
@@ -28,9 +27,10 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
28
27
|
// the benefit of doing so is fairly minor, and it's going to be natively supported soon.
|
|
29
28
|
let onBeforeInputFallback = (0, $jyGKS$useEffectEvent)((e)=>{
|
|
30
29
|
let input = inputRef.current;
|
|
30
|
+
if (!input) return;
|
|
31
31
|
// Compute the next value of the input if the event is allowed to proceed.
|
|
32
32
|
// See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
|
|
33
|
-
let nextValue;
|
|
33
|
+
let nextValue = null;
|
|
34
34
|
switch(e.inputType){
|
|
35
35
|
case 'historyUndo':
|
|
36
36
|
case 'historyRedo':
|
|
@@ -69,7 +69,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
69
69
|
if (nextValue == null || !state.validate(nextValue)) e.preventDefault();
|
|
70
70
|
});
|
|
71
71
|
(0, $jyGKS$useEffect)(()=>{
|
|
72
|
-
if (!$d841c8010a73d545$var$supportsNativeBeforeInputEvent()) return;
|
|
72
|
+
if (!$d841c8010a73d545$var$supportsNativeBeforeInputEvent() || !inputRef.current) return;
|
|
73
73
|
let input = inputRef.current;
|
|
74
74
|
input.addEventListener('beforeinput', onBeforeInputFallback, false);
|
|
75
75
|
return ()=>{
|
|
@@ -109,7 +109,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
|
|
|
109
109
|
};
|
|
110
110
|
},
|
|
111
111
|
onCompositionEnd () {
|
|
112
|
-
if (!state.validate(inputRef.current.value)) {
|
|
112
|
+
if (inputRef.current && !state.validate(inputRef.current.value)) {
|
|
113
113
|
// Restore the input value in the DOM immediately so we can synchronously update the selection position.
|
|
114
114
|
// But also update the value in React state as well so it is correct for future updates.
|
|
115
115
|
let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = compositionStartState.current;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"m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AChG,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/useFormattedTextField.ts"],"sourcesContent":["/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {RefObject} from '@react-types/shared';\nimport {TextFieldAria, useTextField} from './useTextField';\nimport {useEffect, useRef} from 'react';\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 | null>): TextFieldAria {\n // All browsers implement the 'beforeinput' event natively except Firefox\n // (currently behind a flag as of Firefox 84). React's polyfill does not\n // run in all cases that the native event fires, e.g. when deleting text.\n // Use the native event if available so that we can prevent invalid deletions.\n // We do not attempt to polyfill this in Firefox since it would be very complicated,\n // the benefit of doing so is fairly minor, and it's going to be natively supported soon.\n let onBeforeInputFallback = useEffectEvent((e: InputEvent) => {\n let input = inputRef.current;\n\n // Compute the next value of the input if the event is allowed to proceed.\n // See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.\n let nextValue: string;\n switch (e.inputType) {\n case 'historyUndo':\n case 'historyRedo':\n // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,\n // because presumably the input would have already been validated previously.\n return;\n case 'insertLineBreak':\n // Explicitly allow \"insertLineBreak\" event, to allow onSubmit for \"enter\" key. e.data is null in this case.\n return;\n case 'deleteContent':\n case 'deleteByCut':\n case 'deleteByDrag':\n nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n break;\n case 'deleteContentForward':\n // This is potentially incorrect, since the browser may actually delete more than a single UTF-16\n // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters\n // or code points may be deleted. However, in our currently supported locales, there are no such cases.\n // If we support additional locales in the future, this may need to change.\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd + 1)\n : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n break;\n case 'deleteContentBackward':\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart - 1) + input.value.slice(input.selectionStart)\n : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n break;\n case 'deleteSoftLineBackward':\n case 'deleteHardLineBackward':\n nextValue = input.value.slice(input.selectionStart);\n break;\n default:\n if (e.data != null) {\n nextValue =\n input.value.slice(0, input.selectionStart) +\n e.data +\n input.value.slice(input.selectionEnd);\n }\n break;\n }\n\n // If we did not compute a value, or the new value is invalid, prevent the event\n // so that the browser does not update the input text, move the selection, or add to\n // the undo/redo stack.\n if (nextValue == null || !state.validate(nextValue)) {\n e.preventDefault();\n }\n });\n\n useEffect(() => {\n if (!supportsNativeBeforeInputEvent()) {\n return;\n }\n\n let input = inputRef.current;\n input.addEventListener('beforeinput', onBeforeInputFallback, false);\n return () => {\n input.removeEventListener('beforeinput', onBeforeInputFallback, false);\n };\n }, [inputRef, onBeforeInputFallback]);\n\n let onBeforeInput = !supportsNativeBeforeInputEvent()\n ? e => {\n let nextValue =\n e.target.value.slice(0, e.target.selectionStart) +\n e.data +\n e.target.value.slice(e.target.selectionEnd);\n\n if (!state.validate(nextValue)) {\n e.preventDefault();\n }\n }\n : null;\n\n let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps, ...validation} = useTextField(props, inputRef);\n\n let compositionStartState = useRef(null);\n return {\n inputProps: mergeProps(\n textFieldProps,\n {\n onBeforeInput,\n onCompositionStart() {\n // Chrome does not implement Input Events Level 2, which specifies the insertFromComposition\n // and deleteByComposition inputType values for the beforeinput event. These are meant to occur\n // at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are\n // cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,\n // nor would we want to cancel them because the input from the user is incomplete at that point.\n // In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel\n // the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either\n // don't support Input Events Level 2, or beforeinput at all, we store the state of the input when\n // the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.\n // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition\n // are implemented, there is no other way to prevent composed input.\n // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204\n let {value, selectionStart, selectionEnd} = inputRef.current;\n compositionStartState.current = {value, selectionStart, selectionEnd};\n },\n onCompositionEnd() {\n if (!state.validate(inputRef.current.value)) {\n // Restore the input value in the DOM immediately so we can synchronously update the selection position.\n // But also update the value in React state as well so it is correct for future updates.\n let {value, selectionStart, selectionEnd} = compositionStartState.current;\n inputRef.current.value = value;\n inputRef.current.setSelectionRange(selectionStart, selectionEnd);\n state.setInputValue(value);\n }\n }\n }\n ),\n labelProps,\n descriptionProps,\n errorMessageProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useFormattedTextField.module.js.map"}
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAcD,SAAS;IACP,OAAO,OAAO,WAAW,eACvB,OAAO,UAAU,IACjB,OAAO,WAAW,SAAS,CAAC,eAAe,KAAK;AACpD;AAEO,SAAS,0CAAsB,KAAyB,EAAE,KAA8B,EAAE,QAA4C;IAC3I,yEAAyE;IACzE,wEAAwE;IACxE,yEAAyE;IACzE,8EAA8E;IAC9E,oFAAoF;IACpF,yFAAyF;IACzF,IAAI,wBAAwB,CAAA,GAAA,qBAAa,EAAE,CAAC;QAC1C,IAAI,QAAQ,SAAS,OAAO;QAC5B,IAAI,CAAC,OACH;QAGF,0EAA0E;QAC1E,4GAA4G;QAC5G,IAAI,YAA2B;QAC/B,OAAQ,EAAE,SAAS;YACjB,KAAK;YACL,KAAK;gBACH,4FAA4F;gBAC5F,6EAA6E;gBAC7E;YACF,KAAK;gBACH,4GAA4G;gBAC5G;YACF,KAAK;YACL,KAAK;YACL,KAAK;gBACH,YAAY,MAAM,KAAK,CAAC,KAAK,CAAC,GAAG,MAAM,cAAc,IAAK,MAAM,KAAK,CAAC,KAAK,CAAC,MAAM,YAAY;gBAC9F;YACF,KAAK;gBACH,iGAAiG;gBACjG,kGAAkG;gBAClG,uGAAuG;gBACvG,2EAA2E;gBAC3E,YAAY,MAAM,YAAY,KAAK,MAAM,cAAc,GACnD,MAAM,KAAK,CAAC,K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N,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,YAAY;QAE5C,IAAI,CAAC,MAAM,QAAQ,CAAC,YAClB,EAAE,cAAc;IAEpB,IACE;IAEJ,IAAI,cAAC,UAAU,EAAE,YAAY,cAAc,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,wCAAW,EAAE,OAAO;IAEvH,IAAI,wBAAwB,CAAA,GAAA,aAAK,EAAsF;IACvH,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,OAAO;gBAC5D,sBAAsB,OAAO,GAAG;2BAAC;oCAAO;kCAAgB;gBAAY;YACtE;YACA;gBACE,IAAI,SAAS,OAAO,IAAI,CAAC,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC,KAAK,GAAG;oBAC/D,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/useFormattedTextField.ts"],"sourcesContent":["/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {RefObject} from '@react-types/shared';\nimport {TextFieldAria, useTextField} from './useTextField';\nimport {useEffect, useRef} from 'react';\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 typeof InputEvent.prototype.getTargetRanges === 'function';\n}\n\nexport function useFormattedTextField(props: AriaTextFieldProps, state: FormattedTextFieldState, inputRef: RefObject<HTMLInputElement | null>): 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 if (!input) {\n return;\n }\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 | null = null;\n switch (e.inputType) {\n case 'historyUndo':\n case 'historyRedo':\n // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,\n // because presumably the input would have already been validated previously.\n return;\n case 'insertLineBreak':\n // Explicitly allow \"insertLineBreak\" event, to allow onSubmit for \"enter\" key. e.data is null in this case.\n return;\n case 'deleteContent':\n case 'deleteByCut':\n case 'deleteByDrag':\n nextValue = input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);\n break;\n case 'deleteContentForward':\n // This is potentially incorrect, since the browser may actually delete more than a single UTF-16\n // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters\n // or code points may be deleted. However, in our currently supported locales, there are no such cases.\n // If we support additional locales in the future, this may need to change.\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd! + 1)\n : input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);\n break;\n case 'deleteContentBackward':\n nextValue = input.selectionEnd === input.selectionStart\n ? input.value.slice(0, input.selectionStart! - 1) + input.value.slice(input.selectionStart!)\n : input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);\n break;\n case 'deleteSoftLineBackward':\n case 'deleteHardLineBackward':\n nextValue = input.value.slice(input.selectionStart!);\n break;\n default:\n if (e.data != null) {\n nextValue =\n input.value.slice(0, input.selectionStart!) +\n e.data +\n input.value.slice(input.selectionEnd!);\n }\n break;\n }\n\n // If we did not compute a value, or the new value is invalid, prevent the event\n // so that the browser does not update the input text, move the selection, or add to\n // the undo/redo stack.\n if (nextValue == null || !state.validate(nextValue)) {\n e.preventDefault();\n }\n });\n\n useEffect(() => {\n if (!supportsNativeBeforeInputEvent() || !inputRef.current) {\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<{value: string, selectionStart: number | null, selectionEnd: number | null} | null>(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 (inputRef.current && !state.validate(inputRef.current.value)) {\n // Restore the input value in the DOM immediately so we can synchronously update the selection position.\n // But also update the value in React state as well so it is correct for future updates.\n let {value, selectionStart, selectionEnd} = compositionStartState.current!;\n inputRef.current.value = value;\n inputRef.current.setSelectionRange(selectionStart, selectionEnd);\n state.setInputValue(value);\n }\n }\n }\n ),\n labelProps,\n descriptionProps,\n errorMessageProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useFormattedTextField.module.js.map"}
|
|
@@ -83,6 +83,7 @@ function $9076f978e02df845$export$712718f7aec83d5(props, ref) {
|
|
|
83
83
|
'aria-activedescendant': props['aria-activedescendant'],
|
|
84
84
|
'aria-autocomplete': props['aria-autocomplete'],
|
|
85
85
|
'aria-haspopup': props['aria-haspopup'],
|
|
86
|
+
'aria-controls': props['aria-controls'],
|
|
86
87
|
value: value,
|
|
87
88
|
onChange: (e)=>setValue(e.target.value),
|
|
88
89
|
autoComplete: props.autoComplete,
|
|
@@ -92,6 +93,8 @@ function $9076f978e02df845$export$712718f7aec83d5(props, ref) {
|
|
|
92
93
|
name: props.name,
|
|
93
94
|
placeholder: props.placeholder,
|
|
94
95
|
inputMode: props.inputMode,
|
|
96
|
+
autoCorrect: props.autoCorrect,
|
|
97
|
+
spellCheck: props.spellCheck,
|
|
95
98
|
// Clipboard events
|
|
96
99
|
onCopy: props.onCopy,
|
|
97
100
|
onCut: props.onCut,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAmGM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,aACb,OAAO,4BACP,qBAAqB,QACtB,GAAqD;IACtD,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,2CAAiB,EAAU,MAAM,KAAK,EAAE,MAAM,YAAY,IAAI,IAAI,MAAM,QAAQ;IACxG,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,OAAO;IAC3C,IAAI,kBAAkB,CAAA,GAAA,8CAAqB,EAAE;QAC3C,GAAG,KAAK;eACR;IACF;IACA,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,gBAAgB,iBAAiB;IACxF,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;QAC3E,GAAG,KAAK;mBACR;QACA,cAAc,MAAM,YAAY,IAAI;IACtC;IACA,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,MAAM,iBAAiB;cACrB;QACA,SAAS,MAAM,OAAO;IACxB;IAEA,CAAA,GAAA,kCAAW,EAAE,KAAK,OAAO;IACzB,CAAA,GAAA,sCAAgB,EAAE,OAAO,iBAAiB;IAE1C,CAAA,GAAA,sBAAQ,EAAE;QACR,wG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cAAc;YACjB,GAAG,UAAU;QACf;0BAEF;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/textfield/src/useTextField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {\n ChangeEvent,\n HTMLAttributes,\n type JSX,\n LabelHTMLAttributes,\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 = JSX.IntrinsicElements;\n\ntype DefaultElementType = 'input';\n\n/**\n * The intrinsic HTML element names that `useTextField` supports; e.g. `input`,\n * `textarea`.\n */\ntype TextFieldIntrinsicElements = keyof Pick<IntrinsicHTMLElements, 'input' | 'textarea'>;\n\n/**\n * The HTML element interfaces that `useTextField` supports based on what is\n * defined for `TextFieldIntrinsicElements`; e.g. `HTMLInputElement`,\n * `HTMLTextAreaElement`.\n */\ntype TextFieldHTMLElementType = Pick<IntrinsicHTMLElements, TextFieldIntrinsicElements>;\n\n/**\n * The HTML attributes interfaces that `useTextField` supports based on what\n * is defined for `TextFieldIntrinsicElements`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldHTMLAttributesType = Pick<IntrinsicHTMLAttributes, TextFieldIntrinsicElements>;\n\n/**\n * The type of `inputProps` returned by `useTextField`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldInputProps<T extends TextFieldIntrinsicElements> = TextFieldHTMLAttributesType[T];\n\nexport interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps {\n /**\n * The HTML element used to render the input, e.g. 'input', or 'textarea'.\n * It determines whether certain HTML attributes will be included in `inputProps`.\n * For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).\n * @default 'input'\n */\n inputElementType?: T,\n /**\n * Controls whether inputted text is automatically capitalized and, if so, in what manner.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize).\n */\n autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'\n}\n\n/**\n * The type of `ref` object that can be passed to `useTextField` based on the given\n * intrinsic HTML element name; e.g.`RefObject<HTMLInputElement>`,\n * `RefObject<HTMLTextAreaElement>`.\n */\ntype TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T] | null>;\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 : undefined,\n {\n disabled: isDisabled,\n readOnly: isReadOnly,\n required: isRequired && validationBehavior === 'native',\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n 'aria-invalid': isInvalid || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-activedescendant': props['aria-activedescendant'],\n 'aria-autocomplete': props['aria-autocomplete'],\n 'aria-haspopup': props['aria-haspopup'],\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),\n autoComplete: props.autoComplete,\n autoCapitalize: props.autoCapitalize,\n maxLength: props.maxLength,\n minLength: props.minLength,\n name: props.name,\n placeholder: props.placeholder,\n inputMode: props.inputMode,\n\n // Clipboard events\n onCopy: props.onCopy,\n onCut: props.onCut,\n onPaste: props.onPaste,\n\n // Composition events\n onCompositionEnd: props.onCompositionEnd,\n onCompositionStart: props.onCompositionStart,\n onCompositionUpdate: props.onCompositionUpdate,\n\n // Selection events\n onSelect: props.onSelect,\n\n // Input events\n onBeforeInput: props.onBeforeInput,\n onInput: props.onInput,\n ...focusableProps,\n ...fieldProps\n }\n ),\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useTextField.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAmGM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,aACb,OAAO,4BACP,qBAAqB,QACtB,GAAG;IACJ,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,EAA+B,OAAO;IACxE,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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M,MAAM,IAAI;YAChB,aAAa,MAAM,WAAW;YAC9B,WAAW,MAAM,SAAS;YAC1B,aAAa,MAAM,WAAW;YAC9B,YAAY,MAAM,UAAU;YAE5B,mBAAmB;YACnB,QAAQ,MAAM,MAAM;YACpB,OAAO,MAAM,KAAK;YAClB,SAAS,MAAM,OAAO;YAEtB,qBAAqB;YACrB,kBAAkB,MAAM,gBAAgB;YACxC,oBAAoB,MAAM,kBAAkB;YAC5C,qBAAqB,MAAM,mBAAmB;YAE9C,mBAAmB;YACnB,UAAU,MAAM,QAAQ;YAExB,eAAe;YACf,eAAe,MAAM,aAAa;YAClC,SAAS,MAAM,OAAO;YACtB,GAAG,cAAc;YACjB,GAAG,UAAU;QACf;0BAEF;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/textfield/src/useTextField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {\n ChangeEvent,\n HTMLAttributes,\n type JSX,\n LabelHTMLAttributes,\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 = JSX.IntrinsicElements;\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<TextFieldHTMLElementType[T]> {\n /**\n * The HTML element used to render the input, e.g. 'input', or 'textarea'.\n * It determines whether certain HTML attributes will be included in `inputProps`.\n * For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).\n * @default 'input'\n */\n inputElementType?: T,\n /**\n * Controls whether inputted text is automatically capitalized and, if so, in what manner.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize).\n */\n autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'\n}\n\n/**\n * The type of `ref` object that can be passed to `useTextField` based on the given\n * intrinsic HTML element name; e.g.`RefObject<HTMLInputElement>`,\n * `RefObject<HTMLTextAreaElement>`.\n */\ntype TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T] | null>;\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 } = props;\n let [value, setValue] = useControlledState<string>(props.value, props.defaultValue || '', props.onChange);\n let {focusableProps} = useFocusable<TextFieldHTMLElementType[T]>(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 : undefined,\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 'aria-controls': props['aria-controls'],\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 autoCorrect: props.autoCorrect,\n spellCheck: props.spellCheck,\n\n // Clipboard events\n onCopy: props.onCopy,\n onCut: props.onCut,\n onPaste: props.onPaste,\n\n // Composition events\n onCompositionEnd: props.onCompositionEnd,\n onCompositionStart: props.onCompositionStart,\n onCompositionUpdate: props.onCompositionUpdate,\n\n // Selection events\n onSelect: props.onSelect,\n\n // Input events\n onBeforeInput: props.onBeforeInput,\n onInput: props.onInput,\n ...focusableProps,\n ...fieldProps\n }\n ),\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useTextField.main.js.map"}
|
package/dist/useTextField.mjs
CHANGED
|
@@ -77,6 +77,7 @@ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
|
77
77
|
'aria-activedescendant': props['aria-activedescendant'],
|
|
78
78
|
'aria-autocomplete': props['aria-autocomplete'],
|
|
79
79
|
'aria-haspopup': props['aria-haspopup'],
|
|
80
|
+
'aria-controls': props['aria-controls'],
|
|
80
81
|
value: value,
|
|
81
82
|
onChange: (e)=>setValue(e.target.value),
|
|
82
83
|
autoComplete: props.autoComplete,
|
|
@@ -86,6 +87,8 @@ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
|
86
87
|
name: props.name,
|
|
87
88
|
placeholder: props.placeholder,
|
|
88
89
|
inputMode: props.inputMode,
|
|
90
|
+
autoCorrect: props.autoCorrect,
|
|
91
|
+
spellCheck: props.spellCheck,
|
|
89
92
|
// Clipboard events
|
|
90
93
|
onCopy: props.onCopy,
|
|
91
94
|
onCut: props.onCut,
|
|
@@ -77,6 +77,7 @@ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
|
77
77
|
'aria-activedescendant': props['aria-activedescendant'],
|
|
78
78
|
'aria-autocomplete': props['aria-autocomplete'],
|
|
79
79
|
'aria-haspopup': props['aria-haspopup'],
|
|
80
|
+
'aria-controls': props['aria-controls'],
|
|
80
81
|
value: value,
|
|
81
82
|
onChange: (e)=>setValue(e.target.value),
|
|
82
83
|
autoComplete: props.autoComplete,
|
|
@@ -86,6 +87,8 @@ function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
|
|
|
86
87
|
name: props.name,
|
|
87
88
|
placeholder: props.placeholder,
|
|
88
89
|
inputMode: props.inputMode,
|
|
90
|
+
autoCorrect: props.autoCorrect,
|
|
91
|
+
spellCheck: props.spellCheck,
|
|
89
92
|
// Clipboard events
|
|
90
93
|
onCopy: props.onCopy,
|
|
91
94
|
onCut: props.onCut,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAmGM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,aACb,OAAO,4BACP,q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;YACV,UAAU;YACV,UAAU,cAAc,uBAAuB;YAC/C,iBAAiB,AAAC,cAAc,uBAAuB,UAAW;YAClE,gBAAgB,aAAa;YAC7B,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,yBAAyB,KAAK,CAAC,wBAAwB;YACvD,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;mBACvC;YACA,UAAU,CAAC,IAAqC,SAAS,EAAE,MAAM,CAAC,KAAK;YACvE,cAAc,MAAM,YAAY;YAChC,gBAAgB,MAAM,cAAc;YACpC,WAAW,MAAM,SAAS;YAC1B,WAAW,MAAM,SAAS;YAC1B,MAAM,MAAM,IAAI;YAChB,aAAa,MAAM,WAAW;YAC9B,WAAW,MAAM,SAAS;YAE1B,mBAAmB;YACnB,QAAQ,MAAM,MAAM;YACpB,OAAO,MAAM,KAAK;YAClB,SAAS,MAAM,OAAO;YAEtB,qBAAqB;YACrB,kBAAkB,MAAM,gBAAgB;YACxC,oBAAoB,MAAM,kBAAkB;YAC5C,qBAAqB,MAAM,mBAAmB;YAE9C,mBAAmB;YACnB,UAAU,MAAM,QAAQ;YAExB,eAAe;YACf,eAAe,MAAM,aAAa;YAClC,SAAS,MAAM,OAAO;YACtB,GAAG,cAAc;YACjB,GAAG,UAAU;QACf;0BAEF;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/textfield/src/useTextField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {\n ChangeEvent,\n HTMLAttributes,\n type JSX,\n LabelHTMLAttributes,\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 = JSX.IntrinsicElements;\n\ntype DefaultElementType = 'input';\n\n/**\n * The intrinsic HTML element names that `useTextField` supports; e.g. `input`,\n * `textarea`.\n */\ntype TextFieldIntrinsicElements = keyof Pick<IntrinsicHTMLElements, 'input' | 'textarea'>;\n\n/**\n * The HTML element interfaces that `useTextField` supports based on what is\n * defined for `TextFieldIntrinsicElements`; e.g. `HTMLInputElement`,\n * `HTMLTextAreaElement`.\n */\ntype TextFieldHTMLElementType = Pick<IntrinsicHTMLElements, TextFieldIntrinsicElements>;\n\n/**\n * The HTML attributes interfaces that `useTextField` supports based on what\n * is defined for `TextFieldIntrinsicElements`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldHTMLAttributesType = Pick<IntrinsicHTMLAttributes, TextFieldIntrinsicElements>;\n\n/**\n * The type of `inputProps` returned by `useTextField`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldInputProps<T extends TextFieldIntrinsicElements> = TextFieldHTMLAttributesType[T];\n\nexport interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps {\n /**\n * The HTML element used to render the input, e.g. 'input', or 'textarea'.\n * It determines whether certain HTML attributes will be included in `inputProps`.\n * For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).\n * @default 'input'\n */\n inputElementType?: T,\n /**\n * Controls whether inputted text is automatically capitalized and, if so, in what manner.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize).\n */\n autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'\n}\n\n/**\n * The type of `ref` object that can be passed to `useTextField` based on the given\n * intrinsic HTML element name; e.g.`RefObject<HTMLInputElement>`,\n * `RefObject<HTMLTextAreaElement>`.\n */\ntype TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T] | null>;\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 : undefined,\n {\n disabled: isDisabled,\n readOnly: isReadOnly,\n required: isRequired && validationBehavior === 'native',\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n 'aria-invalid': isInvalid || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-activedescendant': props['aria-activedescendant'],\n 'aria-autocomplete': props['aria-autocomplete'],\n 'aria-haspopup': props['aria-haspopup'],\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),\n autoComplete: props.autoComplete,\n autoCapitalize: props.autoCapitalize,\n maxLength: props.maxLength,\n minLength: props.minLength,\n name: props.name,\n placeholder: props.placeholder,\n inputMode: props.inputMode,\n\n // Clipboard events\n onCopy: props.onCopy,\n onCut: props.onCut,\n onPaste: props.onPaste,\n\n // Composition events\n onCompositionEnd: props.onCompositionEnd,\n onCompositionStart: props.onCompositionStart,\n onCompositionUpdate: props.onCompositionUpdate,\n\n // Selection events\n onSelect: props.onSelect,\n\n // Input events\n onBeforeInput: props.onBeforeInput,\n onInput: props.onInput,\n ...focusableProps,\n ...fieldProps\n }\n ),\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useTextField.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAmGM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,aACb,OAAO,4BACP,qBAAqB,QACtB,GAAG;IACJ,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,yBAAiB,EAAU,MAAM,KAAK,EAAE,MAAM,YAAY,IAAI,IAAI,MAAM,QAAQ;IACxG,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAA+B,OAAO;IACxE,IAAI,kBAAkB,CAAA,GAAA,6BAAqB,EAAE;QAC3C,GAAG,KAAK;eACR;IACF;IACA,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,gBAAgB,iBAAiB;IACxF,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC3E,GAAG,KAAK;mBACR;QACA,cAAc,MAAM,YAAY,IAAI;IACtC;IACA,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,MAAM,iBAAiB;cACrB;QACA,SAAS,MAAM,OAAO;IACxB;IAEA,CAAA,GAAA,mBAAW,EAAE,KAAK,OAAO;IACzB,CAAA,GAAA,wBAAgB,EAAE,OAAO,iBAAiB;IAE1C,CAAA,GAAA,gBAAQ,EAAE;QACR,wGAAwG;QACxG,gGAAgG;QAChG,4FAA4F;QAC5F,2FAA2F;QAC3F,wBAAwB;QACxB,iDAAiD;QACjD,iDAAiD;QACjD,IAAI,IAAI,OAAO,YAAY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ACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/textfield/src/useTextField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {\n ChangeEvent,\n HTMLAttributes,\n type JSX,\n LabelHTMLAttributes,\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 = JSX.IntrinsicElements;\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<TextFieldHTMLElementType[T]> {\n /**\n * The HTML element used to render the input, e.g. 'input', or 'textarea'.\n * It determines whether certain HTML attributes will be included in `inputProps`.\n * For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).\n * @default 'input'\n */\n inputElementType?: T,\n /**\n * Controls whether inputted text is automatically capitalized and, if so, in what manner.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize).\n */\n autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters'\n}\n\n/**\n * The type of `ref` object that can be passed to `useTextField` based on the given\n * intrinsic HTML element name; e.g.`RefObject<HTMLInputElement>`,\n * `RefObject<HTMLTextAreaElement>`.\n */\ntype TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T] | null>;\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 } = props;\n let [value, setValue] = useControlledState<string>(props.value, props.defaultValue || '', props.onChange);\n let {focusableProps} = useFocusable<TextFieldHTMLElementType[T]>(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 : undefined,\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 'aria-controls': props['aria-controls'],\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 autoCorrect: props.autoCorrect,\n spellCheck: props.spellCheck,\n\n // Clipboard events\n onCopy: props.onCopy,\n onCut: props.onCut,\n onPaste: props.onPaste,\n\n // Composition events\n onCompositionEnd: props.onCompositionEnd,\n onCompositionStart: props.onCompositionStart,\n onCompositionUpdate: props.onCompositionUpdate,\n\n // Selection events\n onSelect: props.onSelect,\n\n // Input events\n onBeforeInput: props.onBeforeInput,\n onInput: props.onInput,\n ...focusableProps,\n ...fieldProps\n }\n ),\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useTextField.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/textfield",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,21 +22,22 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/focus": "^3.
|
|
26
|
-
"@react-aria/form": "^3.0.
|
|
27
|
-
"@react-aria/label": "^3.7.
|
|
28
|
-
"@react-aria/utils": "^3.
|
|
29
|
-
"@react-stately/form": "^3.
|
|
30
|
-
"@react-stately/utils": "^3.10.
|
|
31
|
-
"@react-types/shared": "^3.
|
|
32
|
-
"@react-types/textfield": "^3.
|
|
25
|
+
"@react-aria/focus": "^3.19.1",
|
|
26
|
+
"@react-aria/form": "^3.0.12",
|
|
27
|
+
"@react-aria/label": "^3.7.14",
|
|
28
|
+
"@react-aria/utils": "^3.27.0",
|
|
29
|
+
"@react-stately/form": "^3.1.1",
|
|
30
|
+
"@react-stately/utils": "^3.10.5",
|
|
31
|
+
"@react-types/shared": "^3.27.0",
|
|
32
|
+
"@react-types/textfield": "^3.11.0",
|
|
33
33
|
"@swc/helpers": "^0.5.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
36
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
37
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
37
38
|
},
|
|
38
39
|
"publishConfig": {
|
|
39
40
|
"access": "public"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "09e7f44bebdc9d89122926b2b439a0a38a2814ea"
|
|
42
43
|
}
|
|
@@ -25,7 +25,6 @@ interface FormattedTextFieldState {
|
|
|
25
25
|
function supportsNativeBeforeInputEvent() {
|
|
26
26
|
return typeof window !== 'undefined' &&
|
|
27
27
|
window.InputEvent &&
|
|
28
|
-
// @ts-ignore
|
|
29
28
|
typeof InputEvent.prototype.getTargetRanges === 'function';
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -38,10 +37,13 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
|
|
|
38
37
|
// the benefit of doing so is fairly minor, and it's going to be natively supported soon.
|
|
39
38
|
let onBeforeInputFallback = useEffectEvent((e: InputEvent) => {
|
|
40
39
|
let input = inputRef.current;
|
|
40
|
+
if (!input) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
41
43
|
|
|
42
44
|
// Compute the next value of the input if the event is allowed to proceed.
|
|
43
45
|
// See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
|
|
44
|
-
let nextValue: string;
|
|
46
|
+
let nextValue: string | null = null;
|
|
45
47
|
switch (e.inputType) {
|
|
46
48
|
case 'historyUndo':
|
|
47
49
|
case 'historyRedo':
|
|
@@ -54,7 +56,7 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
|
|
|
54
56
|
case 'deleteContent':
|
|
55
57
|
case 'deleteByCut':
|
|
56
58
|
case 'deleteByDrag':
|
|
57
|
-
nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
|
|
59
|
+
nextValue = input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);
|
|
58
60
|
break;
|
|
59
61
|
case 'deleteContentForward':
|
|
60
62
|
// This is potentially incorrect, since the browser may actually delete more than a single UTF-16
|
|
@@ -62,24 +64,24 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
|
|
|
62
64
|
// or code points may be deleted. However, in our currently supported locales, there are no such cases.
|
|
63
65
|
// If we support additional locales in the future, this may need to change.
|
|
64
66
|
nextValue = input.selectionEnd === input.selectionStart
|
|
65
|
-
? input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd + 1)
|
|
66
|
-
: input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
|
|
67
|
+
? input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd! + 1)
|
|
68
|
+
: input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);
|
|
67
69
|
break;
|
|
68
70
|
case 'deleteContentBackward':
|
|
69
71
|
nextValue = input.selectionEnd === input.selectionStart
|
|
70
|
-
? input.value.slice(0, input.selectionStart - 1) + input.value.slice(input.selectionStart)
|
|
71
|
-
: input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
|
|
72
|
+
? input.value.slice(0, input.selectionStart! - 1) + input.value.slice(input.selectionStart!)
|
|
73
|
+
: input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);
|
|
72
74
|
break;
|
|
73
75
|
case 'deleteSoftLineBackward':
|
|
74
76
|
case 'deleteHardLineBackward':
|
|
75
|
-
nextValue = input.value.slice(input.selectionStart);
|
|
77
|
+
nextValue = input.value.slice(input.selectionStart!);
|
|
76
78
|
break;
|
|
77
79
|
default:
|
|
78
80
|
if (e.data != null) {
|
|
79
81
|
nextValue =
|
|
80
|
-
input.value.slice(0, input.selectionStart) +
|
|
82
|
+
input.value.slice(0, input.selectionStart!) +
|
|
81
83
|
e.data +
|
|
82
|
-
input.value.slice(input.selectionEnd);
|
|
84
|
+
input.value.slice(input.selectionEnd!);
|
|
83
85
|
}
|
|
84
86
|
break;
|
|
85
87
|
}
|
|
@@ -93,7 +95,7 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
|
|
|
93
95
|
});
|
|
94
96
|
|
|
95
97
|
useEffect(() => {
|
|
96
|
-
if (!supportsNativeBeforeInputEvent()) {
|
|
98
|
+
if (!supportsNativeBeforeInputEvent() || !inputRef.current) {
|
|
97
99
|
return;
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -119,7 +121,7 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
|
|
|
119
121
|
|
|
120
122
|
let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps, ...validation} = useTextField(props, inputRef);
|
|
121
123
|
|
|
122
|
-
let compositionStartState = useRef(null);
|
|
124
|
+
let compositionStartState = useRef<{value: string, selectionStart: number | null, selectionEnd: number | null} | null>(null);
|
|
123
125
|
return {
|
|
124
126
|
inputProps: mergeProps(
|
|
125
127
|
textFieldProps,
|
|
@@ -138,14 +140,14 @@ export function useFormattedTextField(props: AriaTextFieldProps, state: Formatte
|
|
|
138
140
|
// Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
|
|
139
141
|
// are implemented, there is no other way to prevent composed input.
|
|
140
142
|
// See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
|
|
141
|
-
let {value, selectionStart, selectionEnd} = inputRef.current
|
|
143
|
+
let {value, selectionStart, selectionEnd} = inputRef.current!;
|
|
142
144
|
compositionStartState.current = {value, selectionStart, selectionEnd};
|
|
143
145
|
},
|
|
144
146
|
onCompositionEnd() {
|
|
145
|
-
if (!state.validate(inputRef.current.value)) {
|
|
147
|
+
if (inputRef.current && !state.validate(inputRef.current.value)) {
|
|
146
148
|
// Restore the input value in the DOM immediately so we can synchronously update the selection position.
|
|
147
149
|
// But also update the value in React state as well so it is correct for future updates.
|
|
148
|
-
let {value, selectionStart, selectionEnd} = compositionStartState.current
|
|
150
|
+
let {value, selectionStart, selectionEnd} = compositionStartState.current!;
|
|
149
151
|
inputRef.current.value = value;
|
|
150
152
|
inputRef.current.setSelectionRange(selectionStart, selectionEnd);
|
|
151
153
|
state.setInputValue(value);
|
package/src/useTextField.ts
CHANGED
|
@@ -69,7 +69,7 @@ type TextFieldHTMLAttributesType = Pick<IntrinsicHTMLAttributes, TextFieldIntrin
|
|
|
69
69
|
*/
|
|
70
70
|
type TextFieldInputProps<T extends TextFieldIntrinsicElements> = TextFieldHTMLAttributesType[T];
|
|
71
71
|
|
|
72
|
-
export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps {
|
|
72
|
+
export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps<TextFieldHTMLElementType[T]> {
|
|
73
73
|
/**
|
|
74
74
|
* The HTML element used to render the input, e.g. 'input', or 'textarea'.
|
|
75
75
|
* It determines whether certain HTML attributes will be included in `inputProps`.
|
|
@@ -118,9 +118,9 @@ export function useTextField<T extends TextFieldIntrinsicElements = DefaultEleme
|
|
|
118
118
|
isReadOnly = false,
|
|
119
119
|
type = 'text',
|
|
120
120
|
validationBehavior = 'aria'
|
|
121
|
-
}
|
|
121
|
+
} = props;
|
|
122
122
|
let [value, setValue] = useControlledState<string>(props.value, props.defaultValue || '', props.onChange);
|
|
123
|
-
let {focusableProps} = useFocusable(props, ref);
|
|
123
|
+
let {focusableProps} = useFocusable<TextFieldHTMLElementType[T]>(props, ref);
|
|
124
124
|
let validationState = useFormValidationState({
|
|
125
125
|
...props,
|
|
126
126
|
value
|
|
@@ -174,6 +174,7 @@ export function useTextField<T extends TextFieldIntrinsicElements = DefaultEleme
|
|
|
174
174
|
'aria-activedescendant': props['aria-activedescendant'],
|
|
175
175
|
'aria-autocomplete': props['aria-autocomplete'],
|
|
176
176
|
'aria-haspopup': props['aria-haspopup'],
|
|
177
|
+
'aria-controls': props['aria-controls'],
|
|
177
178
|
value,
|
|
178
179
|
onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),
|
|
179
180
|
autoComplete: props.autoComplete,
|
|
@@ -183,6 +184,8 @@ export function useTextField<T extends TextFieldIntrinsicElements = DefaultEleme
|
|
|
183
184
|
name: props.name,
|
|
184
185
|
placeholder: props.placeholder,
|
|
185
186
|
inputMode: props.inputMode,
|
|
187
|
+
autoCorrect: props.autoCorrect,
|
|
188
|
+
spellCheck: props.spellCheck,
|
|
186
189
|
|
|
187
190
|
// Clipboard events
|
|
188
191
|
onCopy: props.onCopy,
|