@react-aria/searchfield 3.8.12 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +2 -2
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +15 -18
- package/src/index.ts +3 -3
- package/dist/ar-AE.main.js +0 -6
- package/dist/ar-AE.main.js.map +0 -1
- package/dist/ar-AE.mjs +0 -8
- package/dist/ar-AE.module.js +0 -8
- package/dist/ar-AE.module.js.map +0 -1
- package/dist/bg-BG.main.js +0 -6
- package/dist/bg-BG.main.js.map +0 -1
- package/dist/bg-BG.mjs +0 -8
- package/dist/bg-BG.module.js +0 -8
- package/dist/bg-BG.module.js.map +0 -1
- package/dist/cs-CZ.main.js +0 -6
- package/dist/cs-CZ.main.js.map +0 -1
- package/dist/cs-CZ.mjs +0 -8
- package/dist/cs-CZ.module.js +0 -8
- package/dist/cs-CZ.module.js.map +0 -1
- package/dist/da-DK.main.js +0 -6
- package/dist/da-DK.main.js.map +0 -1
- package/dist/da-DK.mjs +0 -8
- package/dist/da-DK.module.js +0 -8
- package/dist/da-DK.module.js.map +0 -1
- package/dist/de-DE.main.js +0 -6
- package/dist/de-DE.main.js.map +0 -1
- package/dist/de-DE.mjs +0 -8
- package/dist/de-DE.module.js +0 -8
- package/dist/de-DE.module.js.map +0 -1
- package/dist/el-GR.main.js +0 -6
- package/dist/el-GR.main.js.map +0 -1
- package/dist/el-GR.mjs +0 -8
- package/dist/el-GR.module.js +0 -8
- package/dist/el-GR.module.js.map +0 -1
- package/dist/en-US.main.js +0 -6
- package/dist/en-US.main.js.map +0 -1
- package/dist/en-US.mjs +0 -8
- package/dist/en-US.module.js +0 -8
- package/dist/en-US.module.js.map +0 -1
- package/dist/es-ES.main.js +0 -6
- package/dist/es-ES.main.js.map +0 -1
- package/dist/es-ES.mjs +0 -8
- package/dist/es-ES.module.js +0 -8
- package/dist/es-ES.module.js.map +0 -1
- package/dist/et-EE.main.js +0 -6
- package/dist/et-EE.main.js.map +0 -1
- package/dist/et-EE.mjs +0 -8
- package/dist/et-EE.module.js +0 -8
- package/dist/et-EE.module.js.map +0 -1
- package/dist/fi-FI.main.js +0 -6
- package/dist/fi-FI.main.js.map +0 -1
- package/dist/fi-FI.mjs +0 -8
- package/dist/fi-FI.module.js +0 -8
- package/dist/fi-FI.module.js.map +0 -1
- package/dist/fr-FR.main.js +0 -6
- package/dist/fr-FR.main.js.map +0 -1
- package/dist/fr-FR.mjs +0 -8
- package/dist/fr-FR.module.js +0 -8
- package/dist/fr-FR.module.js.map +0 -1
- package/dist/he-IL.main.js +0 -6
- package/dist/he-IL.main.js.map +0 -1
- package/dist/he-IL.mjs +0 -8
- package/dist/he-IL.module.js +0 -8
- package/dist/he-IL.module.js.map +0 -1
- package/dist/hr-HR.main.js +0 -6
- package/dist/hr-HR.main.js.map +0 -1
- package/dist/hr-HR.mjs +0 -8
- package/dist/hr-HR.module.js +0 -8
- package/dist/hr-HR.module.js.map +0 -1
- package/dist/hu-HU.main.js +0 -6
- package/dist/hu-HU.main.js.map +0 -1
- package/dist/hu-HU.mjs +0 -8
- package/dist/hu-HU.module.js +0 -8
- package/dist/hu-HU.module.js.map +0 -1
- package/dist/intlStrings.main.js +0 -108
- package/dist/intlStrings.main.js.map +0 -1
- package/dist/intlStrings.mjs +0 -110
- package/dist/intlStrings.module.js +0 -110
- package/dist/intlStrings.module.js.map +0 -1
- package/dist/it-IT.main.js +0 -6
- package/dist/it-IT.main.js.map +0 -1
- package/dist/it-IT.mjs +0 -8
- package/dist/it-IT.module.js +0 -8
- package/dist/it-IT.module.js.map +0 -1
- package/dist/ja-JP.main.js +0 -6
- package/dist/ja-JP.main.js.map +0 -1
- package/dist/ja-JP.mjs +0 -8
- package/dist/ja-JP.module.js +0 -8
- package/dist/ja-JP.module.js.map +0 -1
- package/dist/ko-KR.main.js +0 -6
- package/dist/ko-KR.main.js.map +0 -1
- package/dist/ko-KR.mjs +0 -8
- package/dist/ko-KR.module.js +0 -8
- package/dist/ko-KR.module.js.map +0 -1
- package/dist/lt-LT.main.js +0 -6
- package/dist/lt-LT.main.js.map +0 -1
- package/dist/lt-LT.mjs +0 -8
- package/dist/lt-LT.module.js +0 -8
- package/dist/lt-LT.module.js.map +0 -1
- package/dist/lv-LV.main.js +0 -6
- package/dist/lv-LV.main.js.map +0 -1
- package/dist/lv-LV.mjs +0 -8
- package/dist/lv-LV.module.js +0 -8
- package/dist/lv-LV.module.js.map +0 -1
- package/dist/nb-NO.main.js +0 -6
- package/dist/nb-NO.main.js.map +0 -1
- package/dist/nb-NO.mjs +0 -8
- package/dist/nb-NO.module.js +0 -8
- package/dist/nb-NO.module.js.map +0 -1
- package/dist/nl-NL.main.js +0 -6
- package/dist/nl-NL.main.js.map +0 -1
- package/dist/nl-NL.mjs +0 -8
- package/dist/nl-NL.module.js +0 -8
- package/dist/nl-NL.module.js.map +0 -1
- package/dist/pl-PL.main.js +0 -6
- package/dist/pl-PL.main.js.map +0 -1
- package/dist/pl-PL.mjs +0 -8
- package/dist/pl-PL.module.js +0 -8
- package/dist/pl-PL.module.js.map +0 -1
- package/dist/pt-BR.main.js +0 -6
- package/dist/pt-BR.main.js.map +0 -1
- package/dist/pt-BR.mjs +0 -8
- package/dist/pt-BR.module.js +0 -8
- package/dist/pt-BR.module.js.map +0 -1
- package/dist/pt-PT.main.js +0 -6
- package/dist/pt-PT.main.js.map +0 -1
- package/dist/pt-PT.mjs +0 -8
- package/dist/pt-PT.module.js +0 -8
- package/dist/pt-PT.module.js.map +0 -1
- package/dist/ro-RO.main.js +0 -6
- package/dist/ro-RO.main.js.map +0 -1
- package/dist/ro-RO.mjs +0 -8
- package/dist/ro-RO.module.js +0 -8
- package/dist/ro-RO.module.js.map +0 -1
- package/dist/ru-RU.main.js +0 -6
- package/dist/ru-RU.main.js.map +0 -1
- package/dist/ru-RU.mjs +0 -8
- package/dist/ru-RU.module.js +0 -8
- package/dist/ru-RU.module.js.map +0 -1
- package/dist/sk-SK.main.js +0 -6
- package/dist/sk-SK.main.js.map +0 -1
- package/dist/sk-SK.mjs +0 -8
- package/dist/sk-SK.module.js +0 -8
- package/dist/sk-SK.module.js.map +0 -1
- package/dist/sl-SI.main.js +0 -6
- package/dist/sl-SI.main.js.map +0 -1
- package/dist/sl-SI.mjs +0 -8
- package/dist/sl-SI.module.js +0 -8
- package/dist/sl-SI.module.js.map +0 -1
- package/dist/sr-SP.main.js +0 -6
- package/dist/sr-SP.main.js.map +0 -1
- package/dist/sr-SP.mjs +0 -8
- package/dist/sr-SP.module.js +0 -8
- package/dist/sr-SP.module.js.map +0 -1
- package/dist/sv-SE.main.js +0 -6
- package/dist/sv-SE.main.js.map +0 -1
- package/dist/sv-SE.mjs +0 -8
- package/dist/sv-SE.module.js +0 -8
- package/dist/sv-SE.module.js.map +0 -1
- package/dist/tr-TR.main.js +0 -6
- package/dist/tr-TR.main.js.map +0 -1
- package/dist/tr-TR.mjs +0 -8
- package/dist/tr-TR.module.js +0 -8
- package/dist/tr-TR.module.js.map +0 -1
- package/dist/types.d.ts +0 -27
- package/dist/types.d.ts.map +0 -1
- package/dist/uk-UA.main.js +0 -6
- package/dist/uk-UA.main.js.map +0 -1
- package/dist/uk-UA.mjs +0 -8
- package/dist/uk-UA.module.js +0 -8
- package/dist/uk-UA.module.js.map +0 -1
- package/dist/useSearchField.main.js +0 -93
- package/dist/useSearchField.main.js.map +0 -1
- package/dist/useSearchField.mjs +0 -88
- package/dist/useSearchField.module.js +0 -88
- package/dist/useSearchField.module.js.map +0 -1
- package/dist/zh-CN.main.js +0 -6
- package/dist/zh-CN.main.js.map +0 -1
- package/dist/zh-CN.mjs +0 -8
- package/dist/zh-CN.module.js +0 -8
- package/dist/zh-CN.module.js.map +0 -1
- package/dist/zh-TW.main.js +0 -6
- package/dist/zh-TW.main.js.map +0 -1
- package/dist/zh-TW.mjs +0 -8
- package/dist/zh-TW.module.js +0 -8
- package/dist/zh-TW.module.js.map +0 -1
- package/src/useSearchField.ts +0 -131
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import $kTEqN$intlStringsmodulejs from "./intlStrings.module.js";
|
|
2
|
-
import {chain as $kTEqN$chain} from "@react-aria/utils";
|
|
3
|
-
import {useLocalizedStringFormatter as $kTEqN$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
4
|
-
import {useTextField as $kTEqN$useTextField} from "@react-aria/textfield";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function $parcel$interopDefault(a) {
|
|
8
|
-
return a && a.__esModule ? a.default : a;
|
|
9
|
-
}
|
|
10
|
-
/*
|
|
11
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
12
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
-
*
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
-
* governing permissions and limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function $4d52238874b24f86$export$9bb30bbe003b82e0(props, state, inputRef) {
|
|
25
|
-
let stringFormatter = (0, $kTEqN$useLocalizedStringFormatter)((0, ($parcel$interopDefault($kTEqN$intlStringsmodulejs))), '@react-aria/searchfield');
|
|
26
|
-
let { isDisabled: isDisabled, isReadOnly: isReadOnly, onSubmit: onSubmit, onClear: onClear, type: type = 'search' } = props;
|
|
27
|
-
let onKeyDown = (e)=>{
|
|
28
|
-
const key = e.key;
|
|
29
|
-
if (key === 'Enter' && (isDisabled || isReadOnly)) e.preventDefault();
|
|
30
|
-
if (isDisabled || isReadOnly) return;
|
|
31
|
-
// for backward compatibility;
|
|
32
|
-
// otherwise, "Enter" on an input would trigger a form submit, the default browser behavior
|
|
33
|
-
if (key === 'Enter' && onSubmit) {
|
|
34
|
-
e.preventDefault();
|
|
35
|
-
onSubmit(state.value);
|
|
36
|
-
}
|
|
37
|
-
if (key === 'Escape') {
|
|
38
|
-
// Also check the inputRef value for the case where the value was set directly on the input element instead of going through
|
|
39
|
-
// the hook
|
|
40
|
-
if (state.value === '' && (!inputRef.current || inputRef.current.value === '')) e.continuePropagation();
|
|
41
|
-
else {
|
|
42
|
-
e.preventDefault();
|
|
43
|
-
state.setValue('');
|
|
44
|
-
if (onClear) onClear();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
let onClearButtonClick = ()=>{
|
|
49
|
-
state.setValue('');
|
|
50
|
-
if (onClear) onClear();
|
|
51
|
-
};
|
|
52
|
-
let onPressStart = ()=>{
|
|
53
|
-
var // this is in PressStart for mobile so that touching the clear button doesn't remove focus from
|
|
54
|
-
// the input and close the keyboard
|
|
55
|
-
_inputRef_current;
|
|
56
|
-
(_inputRef_current = inputRef.current) === null || _inputRef_current === void 0 ? void 0 : _inputRef_current.focus();
|
|
57
|
-
};
|
|
58
|
-
let { labelProps: labelProps, inputProps: inputProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps, ...validation } = (0, $kTEqN$useTextField)({
|
|
59
|
-
...props,
|
|
60
|
-
value: state.value,
|
|
61
|
-
onChange: state.setValue,
|
|
62
|
-
onKeyDown: !isReadOnly ? (0, $kTEqN$chain)(onKeyDown, props.onKeyDown) : props.onKeyDown,
|
|
63
|
-
type: type
|
|
64
|
-
}, inputRef);
|
|
65
|
-
return {
|
|
66
|
-
labelProps: labelProps,
|
|
67
|
-
inputProps: {
|
|
68
|
-
...inputProps,
|
|
69
|
-
// already handled by useSearchFieldState
|
|
70
|
-
defaultValue: undefined
|
|
71
|
-
},
|
|
72
|
-
clearButtonProps: {
|
|
73
|
-
'aria-label': stringFormatter.format('Clear search'),
|
|
74
|
-
excludeFromTabOrder: true,
|
|
75
|
-
preventFocusOnPress: true,
|
|
76
|
-
isDisabled: isDisabled || isReadOnly,
|
|
77
|
-
onPress: onClearButtonClick,
|
|
78
|
-
onPressStart: onPressStart
|
|
79
|
-
},
|
|
80
|
-
descriptionProps: descriptionProps,
|
|
81
|
-
errorMessageProps: errorMessageProps,
|
|
82
|
-
...validation
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export {$4d52238874b24f86$export$9bb30bbe003b82e0 as useSearchField};
|
|
88
|
-
//# sourceMappingURL=useSearchField.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAgCM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,QAA4C;IAE5C,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,cACF,UAAU,cACV,UAAU,YACV,QAAQ,WACR,OAAO,QACP,OAAO,UACR,GAAG;IAEJ,IAAI,YAAY,CAAC;QACf,MAAM,MAAM,EAAE,GAAG;QAEjB,IAAI,QAAQ,WAAY,CAAA,cAAc,UAAS,GAC7C,EAAE,cAAc;QAGlB,IAAI,cAAc,YAChB;QAGF,8BAA8B;QAC9B,2FAA2F;QAC3F,IAAI,QAAQ,WAAW,UAAU;YAC/B,EAAE,cAAc;YAChB,SAAS,MAAM,KAAK;QACtB;QAEA,IAAI,QAAQ;YACV,4HAA4H;YAC5H,WAAW;YACX,IAAI,MAAM,KAAK,KAAK,MAAO,CAAA,CAAC,SAAS,OAAO,IAAI,SAAS,OAAO,CAAC,KAAK,KAAK,EAAC,GAC1E,EAAE,mBAAmB;iBAChB;gBACL,EAAE,cAAc;gBAChB,MAAM,QAAQ,CAAC;gBACf,IAAI,SACF;YAEJ;;IAEJ;IAEA,IAAI,qBAAqB;QACvB,MAAM,QAAQ,CAAC;QAEf,IAAI,SACF;IAEJ;IAEA,IAAI,eAAe;YACjB,+FAA+F;QAC/F,mCAAmC;QACnC;SAAA,oBAAA,SAAS,OAAO,cAAhB,wCAAA,kBAAkB,KAAK;IACzB;IAEA,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,mBAAW,EAAE;QAC9F,GAAG,KAAK;QACR,OAAO,MAAM,KAAK;QAClB,UAAU,MAAM,QAAQ;QACxB,WAAW,CAAC,aAAa,CAAA,GAAA,YAAI,EAAE,WAAW,MAAM,SAAS,IAAI,MAAM,SAAS;cAC5E;IACF,GAAG;IAEH,OAAO;oBACL;QACA,YAAY;YACV,GAAG,UAAU;YACb,yCAAyC;YACzC,cAAc;QAChB;QACA,kBAAkB;YAChB,cAAc,gBAAgB,MAAM,CAAC;YACrC,qBAAqB;YACrB,qBAAqB;YACrB,YAAY,cAAc;YAC1B,SAAS;0BACT;QACF;0BACA;2BACA;QACA,GAAG,UAAU;IACf;AACF","sources":["packages/@react-aria/searchfield/src/useSearchField.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 {AriaButtonProps} from '@react-types/button';\nimport {AriaSearchFieldProps} from '@react-types/searchfield';\nimport {chain} from '@react-aria/utils';\nimport {DOMAttributes, RefObject, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes, LabelHTMLAttributes} from 'react';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {SearchFieldState} from '@react-stately/searchfield';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useTextField} from '@react-aria/textfield';\n\nexport interface SearchFieldAria extends ValidationResult {\n /** Props for the text field's visible label element (if any). */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Props for the clear button. */\n clearButtonProps: AriaButtonProps,\n /** Props for the searchfield's description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the searchfield's error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a search field.\n * @param props - Props for the search field.\n * @param state - State for the search field, as returned by `useSearchFieldState`.\n * @param inputRef - A ref to the input element.\n */\nexport function useSearchField(\n props: AriaSearchFieldProps,\n state: SearchFieldState,\n inputRef: RefObject<HTMLInputElement | null>\n): SearchFieldAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/searchfield');\n let {\n isDisabled,\n isReadOnly,\n onSubmit,\n onClear,\n type = 'search'\n } = props;\n\n let onKeyDown = (e) => {\n const key = e.key;\n\n if (key === 'Enter' && (isDisabled || isReadOnly)) {\n e.preventDefault();\n }\n\n if (isDisabled || isReadOnly) {\n return;\n }\n\n // for backward compatibility;\n // otherwise, \"Enter\" on an input would trigger a form submit, the default browser behavior\n if (key === 'Enter' && onSubmit) {\n e.preventDefault();\n onSubmit(state.value);\n }\n\n if (key === 'Escape') {\n // Also check the inputRef value for the case where the value was set directly on the input element instead of going through\n // the hook\n if (state.value === '' && (!inputRef.current || inputRef.current.value === '')) {\n e.continuePropagation();\n } else {\n e.preventDefault();\n state.setValue('');\n if (onClear) {\n onClear();\n }\n }\n }\n };\n\n let onClearButtonClick = () => {\n state.setValue('');\n\n if (onClear) {\n onClear();\n }\n };\n\n let onPressStart = () => {\n // this is in PressStart for mobile so that touching the clear button doesn't remove focus from\n // the input and close the keyboard\n inputRef.current?.focus();\n };\n\n let {labelProps, inputProps, descriptionProps, errorMessageProps, ...validation} = useTextField({\n ...props,\n value: state.value,\n onChange: state.setValue,\n onKeyDown: !isReadOnly ? chain(onKeyDown, props.onKeyDown) : props.onKeyDown,\n type\n }, inputRef);\n\n return {\n labelProps,\n inputProps: {\n ...inputProps,\n // already handled by useSearchFieldState\n defaultValue: undefined\n },\n clearButtonProps: {\n 'aria-label': stringFormatter.format('Clear search'),\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n isDisabled: isDisabled || isReadOnly,\n onPress: onClearButtonClick,\n onPressStart\n },\n descriptionProps,\n errorMessageProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useSearchField.module.js.map"}
|
package/dist/zh-CN.main.js
DELETED
package/dist/zh-CN.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,iBAAiB;IAAG,gBAAgB,CAAC,gCAAI,CAAC;AAC1C","sources":["packages/@react-aria/searchfield/intl/zh-CN.json"],"sourcesContent":["{\n \"Clear search\": \"清除搜索\"\n}\n"],"names":[],"version":3,"file":"zh-CN.main.js.map"}
|
package/dist/zh-CN.mjs
DELETED
package/dist/zh-CN.module.js
DELETED
package/dist/zh-CN.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";AAAA,4BAAiB;IAAG,gBAAgB,CAAC,gCAAI,CAAC;AAC1C","sources":["packages/@react-aria/searchfield/intl/zh-CN.json"],"sourcesContent":["{\n \"Clear search\": \"清除搜索\"\n}\n"],"names":[],"version":3,"file":"zh-CN.module.js.map"}
|
package/dist/zh-TW.main.js
DELETED
package/dist/zh-TW.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,iBAAiB;IAAG,gBAAgB,CAAC,gDAAM,CAAC;AAC5C","sources":["packages/@react-aria/searchfield/intl/zh-TW.json"],"sourcesContent":["{\n \"Clear search\": \"清除搜尋條件\"\n}\n"],"names":[],"version":3,"file":"zh-TW.main.js.map"}
|
package/dist/zh-TW.mjs
DELETED
package/dist/zh-TW.module.js
DELETED
package/dist/zh-TW.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";AAAA,4BAAiB;IAAG,gBAAgB,CAAC,gDAAM,CAAC;AAC5C","sources":["packages/@react-aria/searchfield/intl/zh-TW.json"],"sourcesContent":["{\n \"Clear search\": \"清除搜尋條件\"\n}\n"],"names":[],"version":3,"file":"zh-TW.module.js.map"}
|
package/src/useSearchField.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaButtonProps} from '@react-types/button';
|
|
14
|
-
import {AriaSearchFieldProps} from '@react-types/searchfield';
|
|
15
|
-
import {chain} from '@react-aria/utils';
|
|
16
|
-
import {DOMAttributes, RefObject, ValidationResult} from '@react-types/shared';
|
|
17
|
-
import {InputHTMLAttributes, LabelHTMLAttributes} from 'react';
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
import intlMessages from '../intl/*.json';
|
|
20
|
-
import {SearchFieldState} from '@react-stately/searchfield';
|
|
21
|
-
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
22
|
-
import {useTextField} from '@react-aria/textfield';
|
|
23
|
-
|
|
24
|
-
export interface SearchFieldAria extends ValidationResult {
|
|
25
|
-
/** Props for the text field's visible label element (if any). */
|
|
26
|
-
labelProps: LabelHTMLAttributes<HTMLLabelElement>,
|
|
27
|
-
/** Props for the input element. */
|
|
28
|
-
inputProps: InputHTMLAttributes<HTMLInputElement>,
|
|
29
|
-
/** Props for the clear button. */
|
|
30
|
-
clearButtonProps: AriaButtonProps,
|
|
31
|
-
/** Props for the searchfield's description element, if any. */
|
|
32
|
-
descriptionProps: DOMAttributes,
|
|
33
|
-
/** Props for the searchfield's error message element, if any. */
|
|
34
|
-
errorMessageProps: DOMAttributes
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Provides the behavior and accessibility implementation for a search field.
|
|
39
|
-
* @param props - Props for the search field.
|
|
40
|
-
* @param state - State for the search field, as returned by `useSearchFieldState`.
|
|
41
|
-
* @param inputRef - A ref to the input element.
|
|
42
|
-
*/
|
|
43
|
-
export function useSearchField(
|
|
44
|
-
props: AriaSearchFieldProps,
|
|
45
|
-
state: SearchFieldState,
|
|
46
|
-
inputRef: RefObject<HTMLInputElement | null>
|
|
47
|
-
): SearchFieldAria {
|
|
48
|
-
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/searchfield');
|
|
49
|
-
let {
|
|
50
|
-
isDisabled,
|
|
51
|
-
isReadOnly,
|
|
52
|
-
onSubmit,
|
|
53
|
-
onClear,
|
|
54
|
-
type = 'search'
|
|
55
|
-
} = props;
|
|
56
|
-
|
|
57
|
-
let onKeyDown = (e) => {
|
|
58
|
-
const key = e.key;
|
|
59
|
-
|
|
60
|
-
if (key === 'Enter' && (isDisabled || isReadOnly)) {
|
|
61
|
-
e.preventDefault();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (isDisabled || isReadOnly) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// for backward compatibility;
|
|
69
|
-
// otherwise, "Enter" on an input would trigger a form submit, the default browser behavior
|
|
70
|
-
if (key === 'Enter' && onSubmit) {
|
|
71
|
-
e.preventDefault();
|
|
72
|
-
onSubmit(state.value);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (key === 'Escape') {
|
|
76
|
-
// Also check the inputRef value for the case where the value was set directly on the input element instead of going through
|
|
77
|
-
// the hook
|
|
78
|
-
if (state.value === '' && (!inputRef.current || inputRef.current.value === '')) {
|
|
79
|
-
e.continuePropagation();
|
|
80
|
-
} else {
|
|
81
|
-
e.preventDefault();
|
|
82
|
-
state.setValue('');
|
|
83
|
-
if (onClear) {
|
|
84
|
-
onClear();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
let onClearButtonClick = () => {
|
|
91
|
-
state.setValue('');
|
|
92
|
-
|
|
93
|
-
if (onClear) {
|
|
94
|
-
onClear();
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
let onPressStart = () => {
|
|
99
|
-
// this is in PressStart for mobile so that touching the clear button doesn't remove focus from
|
|
100
|
-
// the input and close the keyboard
|
|
101
|
-
inputRef.current?.focus();
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
let {labelProps, inputProps, descriptionProps, errorMessageProps, ...validation} = useTextField({
|
|
105
|
-
...props,
|
|
106
|
-
value: state.value,
|
|
107
|
-
onChange: state.setValue,
|
|
108
|
-
onKeyDown: !isReadOnly ? chain(onKeyDown, props.onKeyDown) : props.onKeyDown,
|
|
109
|
-
type
|
|
110
|
-
}, inputRef);
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
labelProps,
|
|
114
|
-
inputProps: {
|
|
115
|
-
...inputProps,
|
|
116
|
-
// already handled by useSearchFieldState
|
|
117
|
-
defaultValue: undefined
|
|
118
|
-
},
|
|
119
|
-
clearButtonProps: {
|
|
120
|
-
'aria-label': stringFormatter.format('Clear search'),
|
|
121
|
-
excludeFromTabOrder: true,
|
|
122
|
-
preventFocusOnPress: true,
|
|
123
|
-
isDisabled: isDisabled || isReadOnly,
|
|
124
|
-
onPress: onClearButtonClick,
|
|
125
|
-
onPressStart
|
|
126
|
-
},
|
|
127
|
-
descriptionProps,
|
|
128
|
-
errorMessageProps,
|
|
129
|
-
...validation
|
|
130
|
-
};
|
|
131
|
-
}
|