@react-aria/searchfield 3.7.5 → 3.7.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AriaButtonProps } from "@react-types/button";
2
2
  import { AriaSearchFieldProps } from "@react-types/searchfield";
3
- import { DOMAttributes, ValidationResult } from "@react-types/shared";
4
- import { InputHTMLAttributes, LabelHTMLAttributes, RefObject } from "react";
3
+ import { DOMAttributes, RefObject, ValidationResult } from "@react-types/shared";
4
+ import { InputHTMLAttributes, LabelHTMLAttributes } from "react";
5
5
  import { SearchFieldState } from "@react-stately/searchfield";
6
6
  export interface SearchFieldAria extends ValidationResult {
7
7
  /** Props for the text field's visible label element (if any). */
@@ -21,7 +21,7 @@ export interface SearchFieldAria extends ValidationResult {
21
21
  * @param state - State for the search field, as returned by `useSearchFieldState`.
22
22
  * @param inputRef - A ref to the input element.
23
23
  */
24
- export function useSearchField(props: AriaSearchFieldProps, state: SearchFieldState, inputRef: RefObject<HTMLInputElement>): SearchFieldAria;
24
+ export function useSearchField(props: AriaSearchFieldProps, state: SearchFieldState, inputRef: RefObject<HTMLInputElement | null>): SearchFieldAria;
25
25
  export type { AriaSearchFieldProps } from '@react-types/searchfield';
26
26
 
27
27
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":";;;;;AAuBA,gCAAiC,SAAQ,gBAAgB;IACvD,iEAAiE;IACjE,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,kCAAkC;IAClC,gBAAgB,EAAE,eAAe,CAAC;IAClC,+DAA+D;IAC/D,gBAAgB,EAAE,aAAa,CAAC;IAChC,iEAAiE;IACjE,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;;GAKG;AACH,+BACE,KAAK,EAAE,oBAAoB,EAC3B,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GACpC,eAAe,CA+EjB;ACjHD,YAAY,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAC","sources":["packages/@react-aria/searchfield/src/packages/@react-aria/searchfield/src/useSearchField.ts","packages/@react-aria/searchfield/src/packages/@react-aria/searchfield/src/index.ts","packages/@react-aria/searchfield/src/index.ts"],"sourcesContent":[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 {useSearchField} from './useSearchField';\nexport type {AriaSearchFieldProps} from '@react-types/searchfield';\nexport type {SearchFieldAria} from './useSearchField';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;;;AAuBA,gCAAiC,SAAQ,gBAAgB;IACvD,iEAAiE;IACjE,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,kCAAkC;IAClC,gBAAgB,EAAE,eAAe,CAAC;IAClC,+DAA+D;IAC/D,gBAAgB,EAAE,aAAa,CAAC;IAChC,iEAAiE;IACjE,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;;GAKG;AACH,+BACE,KAAK,EAAE,oBAAoB,EAC3B,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAC3C,eAAe,CAkFjB;ACpHD,YAAY,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAC","sources":["packages/@react-aria/searchfield/src/packages/@react-aria/searchfield/src/useSearchField.ts","packages/@react-aria/searchfield/src/packages/@react-aria/searchfield/src/index.ts","packages/@react-aria/searchfield/src/index.ts"],"sourcesContent":[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 {useSearchField} from './useSearchField';\nexport type {AriaSearchFieldProps} from '@react-types/searchfield';\nexport type {SearchFieldAria} from './useSearchField';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -29,12 +29,17 @@ $parcel$export(module.exports, "useSearchField", () => $ccae92a71d96d51a$export$
29
29
 
30
30
  function $ccae92a71d96d51a$export$9bb30bbe003b82e0(props, state, inputRef) {
31
31
  let stringFormatter = (0, $2KtRb$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($8e80a08ea739bb00$exports))), '@react-aria/searchfield');
32
- let { isDisabled: isDisabled, isReadOnly: isReadOnly, onSubmit: onSubmit = ()=>{}, onClear: onClear, type: type = 'search' } = props;
32
+ let { isDisabled: isDisabled, isReadOnly: isReadOnly, onSubmit: onSubmit, onClear: onClear, type: type = 'search' } = props;
33
33
  let onKeyDown = (e)=>{
34
34
  const key = e.key;
35
- if (key === 'Enter') e.preventDefault();
35
+ if (key === 'Enter' && (isDisabled || isReadOnly)) e.preventDefault();
36
36
  if (isDisabled || isReadOnly) return;
37
- if (key === 'Enter') onSubmit(state.value);
37
+ // for backward compatibility;
38
+ // otherwise, "Enter" on an input would trigger a form submit, the default browser behavior
39
+ if (key === 'Enter' && onSubmit) {
40
+ e.preventDefault();
41
+ onSubmit(state.value);
42
+ }
38
43
  if (key === 'Escape') {
39
44
  if (state.value === '') e.continuePropagation();
40
45
  else {
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAgCM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,QAAqC;IAErC,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,cACF,UAAU,cACV,UAAU,YACV,WAAW,KAAO,YAClB,OAAO,QACP,OAAO,UACR,GAAG;IAEJ,IAAI,YAAY,CAAC;QACf,MAAM,MAAM,EAAE,GAAG;QAEjB,IAAI,QAAQ,SACV,EAAE,cAAc;QAGlB,IAAI,cAAc,YAChB;QAGF,IAAI,QAAQ,SACV,SAAS,MAAM,KAAK;QAGtB,IAAI,QAAQ;YACV,IAAI,MAAM,KAAK,KAAK,IAClB,EAAE,mBAAmB;iBAChB;gBACL,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,sCAAW,EAAE;QAC9F,GAAG,KAAK;QACR,OAAO,MAAM,KAAK;QAClB,UAAU,MAAM,QAAQ;QACxB,WAAW,CAAC,aAAa,CAAA,GAAA,2BAAI,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,aAAa;YACb,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, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes, LabelHTMLAttributes, RefObject} 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>\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') {\n e.preventDefault();\n }\n\n if (isDisabled || isReadOnly) {\n return;\n }\n\n if (key === 'Enter') {\n onSubmit(state.value);\n }\n\n if (key === 'Escape') {\n if (state.value === '') {\n e.continuePropagation();\n } else {\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 // @ts-ignore\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.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAgCM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,QAA4C;IAE5C,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,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,IAAI,MAAM,KAAK,KAAK,IAClB,EAAE,mBAAmB;iBAChB;gBACL,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,sCAAW,EAAE;QAC9F,GAAG,KAAK;QACR,OAAO,MAAM,KAAK;QAClB,UAAU,MAAM,QAAQ;QACxB,WAAW,CAAC,aAAa,CAAA,GAAA,2BAAI,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,aAAa;YACb,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 if (state.value === '') {\n e.continuePropagation();\n } else {\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 // @ts-ignore\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.main.js.map"}
@@ -23,12 +23,17 @@ function $parcel$interopDefault(a) {
23
23
 
24
24
  function $4d52238874b24f86$export$9bb30bbe003b82e0(props, state, inputRef) {
25
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;
26
+ let { isDisabled: isDisabled, isReadOnly: isReadOnly, onSubmit: onSubmit, onClear: onClear, type: type = 'search' } = props;
27
27
  let onKeyDown = (e)=>{
28
28
  const key = e.key;
29
- if (key === 'Enter') e.preventDefault();
29
+ if (key === 'Enter' && (isDisabled || isReadOnly)) e.preventDefault();
30
30
  if (isDisabled || isReadOnly) return;
31
- if (key === 'Enter') onSubmit(state.value);
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
+ }
32
37
  if (key === 'Escape') {
33
38
  if (state.value === '') e.continuePropagation();
34
39
  else {
@@ -23,12 +23,17 @@ function $parcel$interopDefault(a) {
23
23
 
24
24
  function $4d52238874b24f86$export$9bb30bbe003b82e0(props, state, inputRef) {
25
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;
26
+ let { isDisabled: isDisabled, isReadOnly: isReadOnly, onSubmit: onSubmit, onClear: onClear, type: type = 'search' } = props;
27
27
  let onKeyDown = (e)=>{
28
28
  const key = e.key;
29
- if (key === 'Enter') e.preventDefault();
29
+ if (key === 'Enter' && (isDisabled || isReadOnly)) e.preventDefault();
30
30
  if (isDisabled || isReadOnly) return;
31
- if (key === 'Enter') onSubmit(state.value);
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
+ }
32
37
  if (key === 'Escape') {
33
38
  if (state.value === '') e.continuePropagation();
34
39
  else {
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAgCM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,QAAqC;IAErC,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,cACF,UAAU,cACV,UAAU,YACV,WAAW,KAAO,YAClB,OAAO,QACP,OAAO,UACR,GAAG;IAEJ,IAAI,YAAY,CAAC;QACf,MAAM,MAAM,EAAE,GAAG;QAEjB,IAAI,QAAQ,SACV,EAAE,cAAc;QAGlB,IAAI,cAAc,YAChB;QAGF,IAAI,QAAQ,SACV,SAAS,MAAM,KAAK;QAGtB,IAAI,QAAQ;YACV,IAAI,MAAM,KAAK,KAAK,IAClB,EAAE,mBAAmB;iBAChB;gBACL,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,aAAa;YACb,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, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes, LabelHTMLAttributes, RefObject} 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>\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') {\n e.preventDefault();\n }\n\n if (isDisabled || isReadOnly) {\n return;\n }\n\n if (key === 'Enter') {\n onSubmit(state.value);\n }\n\n if (key === 'Escape') {\n if (state.value === '') {\n e.continuePropagation();\n } else {\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 // @ts-ignore\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"}
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,IAAI,MAAM,KAAK,KAAK,IAClB,EAAE,mBAAmB;iBAChB;gBACL,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,aAAa;YACb,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 if (state.value === '') {\n e.continuePropagation();\n } else {\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 // @ts-ignore\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/searchfield",
3
- "version": "3.7.5",
3
+ "version": "3.7.6",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,20 +22,20 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/i18n": "^3.11.1",
26
- "@react-aria/textfield": "^3.14.5",
27
- "@react-aria/utils": "^3.24.1",
28
- "@react-stately/searchfield": "^3.5.3",
29
- "@react-types/button": "^3.9.4",
30
- "@react-types/searchfield": "^3.5.5",
31
- "@react-types/shared": "^3.23.1",
25
+ "@react-aria/i18n": "^3.12.0",
26
+ "@react-aria/textfield": "^3.14.6",
27
+ "@react-aria/utils": "^3.25.0",
28
+ "@react-stately/searchfield": "^3.5.4",
29
+ "@react-types/button": "^3.9.5",
30
+ "@react-types/searchfield": "^3.5.6",
31
+ "@react-types/shared": "^3.24.0",
32
32
  "@swc/helpers": "^0.5.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
35
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
40
+ "gitHead": "86d80e3216bc32e75108831cf3a5a720bc849206"
41
41
  }
@@ -13,8 +13,8 @@
13
13
  import {AriaButtonProps} from '@react-types/button';
14
14
  import {AriaSearchFieldProps} from '@react-types/searchfield';
15
15
  import {chain} from '@react-aria/utils';
16
- import {DOMAttributes, ValidationResult} from '@react-types/shared';
17
- import {InputHTMLAttributes, LabelHTMLAttributes, RefObject} from 'react';
16
+ import {DOMAttributes, RefObject, ValidationResult} from '@react-types/shared';
17
+ import {InputHTMLAttributes, LabelHTMLAttributes} from 'react';
18
18
  // @ts-ignore
19
19
  import intlMessages from '../intl/*.json';
20
20
  import {SearchFieldState} from '@react-stately/searchfield';
@@ -43,13 +43,13 @@ export interface SearchFieldAria extends ValidationResult {
43
43
  export function useSearchField(
44
44
  props: AriaSearchFieldProps,
45
45
  state: SearchFieldState,
46
- inputRef: RefObject<HTMLInputElement>
46
+ inputRef: RefObject<HTMLInputElement | null>
47
47
  ): SearchFieldAria {
48
48
  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/searchfield');
49
49
  let {
50
50
  isDisabled,
51
51
  isReadOnly,
52
- onSubmit = () => {},
52
+ onSubmit,
53
53
  onClear,
54
54
  type = 'search'
55
55
  } = props;
@@ -57,7 +57,7 @@ export function useSearchField(
57
57
  let onKeyDown = (e) => {
58
58
  const key = e.key;
59
59
 
60
- if (key === 'Enter') {
60
+ if (key === 'Enter' && (isDisabled || isReadOnly)) {
61
61
  e.preventDefault();
62
62
  }
63
63
 
@@ -65,7 +65,10 @@ export function useSearchField(
65
65
  return;
66
66
  }
67
67
 
68
- if (key === 'Enter') {
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();
69
72
  onSubmit(state.value);
70
73
  }
71
74