@react-spectrum/autocomplete 3.0.0-alpha.9 → 3.0.0-nightly-4980928d3-240906

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.
Files changed (226) hide show
  1. package/dist/MobileSearchAutocomplete.main.js +449 -0
  2. package/dist/MobileSearchAutocomplete.main.js.map +1 -0
  3. package/dist/MobileSearchAutocomplete.mjs +444 -0
  4. package/dist/MobileSearchAutocomplete.module.js +444 -0
  5. package/dist/MobileSearchAutocomplete.module.js.map +1 -0
  6. package/dist/SearchAutocomplete.main.js +293 -0
  7. package/dist/SearchAutocomplete.main.js.map +1 -0
  8. package/dist/SearchAutocomplete.mjs +288 -0
  9. package/dist/SearchAutocomplete.module.js +288 -0
  10. package/dist/SearchAutocomplete.module.js.map +1 -0
  11. package/dist/ar-AE.main.js +9 -0
  12. package/dist/ar-AE.main.js.map +1 -0
  13. package/dist/ar-AE.mjs +11 -0
  14. package/dist/ar-AE.module.js +11 -0
  15. package/dist/ar-AE.module.js.map +1 -0
  16. package/dist/bg-BG.main.js +9 -0
  17. package/dist/bg-BG.main.js.map +1 -0
  18. package/dist/bg-BG.mjs +11 -0
  19. package/dist/bg-BG.module.js +11 -0
  20. package/dist/bg-BG.module.js.map +1 -0
  21. package/dist/cs-CZ.main.js +9 -0
  22. package/dist/cs-CZ.main.js.map +1 -0
  23. package/dist/cs-CZ.mjs +11 -0
  24. package/dist/cs-CZ.module.js +11 -0
  25. package/dist/cs-CZ.module.js.map +1 -0
  26. package/dist/da-DK.main.js +9 -0
  27. package/dist/da-DK.main.js.map +1 -0
  28. package/dist/da-DK.mjs +11 -0
  29. package/dist/da-DK.module.js +11 -0
  30. package/dist/da-DK.module.js.map +1 -0
  31. package/dist/de-DE.main.js +9 -0
  32. package/dist/de-DE.main.js.map +1 -0
  33. package/dist/de-DE.mjs +11 -0
  34. package/dist/de-DE.module.js +11 -0
  35. package/dist/de-DE.module.js.map +1 -0
  36. package/dist/el-GR.main.js +9 -0
  37. package/dist/el-GR.main.js.map +1 -0
  38. package/dist/el-GR.mjs +11 -0
  39. package/dist/el-GR.module.js +11 -0
  40. package/dist/el-GR.module.js.map +1 -0
  41. package/dist/en-US.main.js +9 -0
  42. package/dist/en-US.main.js.map +1 -0
  43. package/dist/en-US.mjs +11 -0
  44. package/dist/en-US.module.js +11 -0
  45. package/dist/en-US.module.js.map +1 -0
  46. package/dist/es-ES.main.js +9 -0
  47. package/dist/es-ES.main.js.map +1 -0
  48. package/dist/es-ES.mjs +11 -0
  49. package/dist/es-ES.module.js +11 -0
  50. package/dist/es-ES.module.js.map +1 -0
  51. package/dist/et-EE.main.js +9 -0
  52. package/dist/et-EE.main.js.map +1 -0
  53. package/dist/et-EE.mjs +11 -0
  54. package/dist/et-EE.module.js +11 -0
  55. package/dist/et-EE.module.js.map +1 -0
  56. package/dist/fi-FI.main.js +9 -0
  57. package/dist/fi-FI.main.js.map +1 -0
  58. package/dist/fi-FI.mjs +11 -0
  59. package/dist/fi-FI.module.js +11 -0
  60. package/dist/fi-FI.module.js.map +1 -0
  61. package/dist/fr-FR.main.js +9 -0
  62. package/dist/fr-FR.main.js.map +1 -0
  63. package/dist/fr-FR.mjs +11 -0
  64. package/dist/fr-FR.module.js +11 -0
  65. package/dist/fr-FR.module.js.map +1 -0
  66. package/dist/he-IL.main.js +9 -0
  67. package/dist/he-IL.main.js.map +1 -0
  68. package/dist/he-IL.mjs +11 -0
  69. package/dist/he-IL.module.js +11 -0
  70. package/dist/he-IL.module.js.map +1 -0
  71. package/dist/hr-HR.main.js +9 -0
  72. package/dist/hr-HR.main.js.map +1 -0
  73. package/dist/hr-HR.mjs +11 -0
  74. package/dist/hr-HR.module.js +11 -0
  75. package/dist/hr-HR.module.js.map +1 -0
  76. package/dist/hu-HU.main.js +9 -0
  77. package/dist/hu-HU.main.js.map +1 -0
  78. package/dist/hu-HU.mjs +11 -0
  79. package/dist/hu-HU.module.js +11 -0
  80. package/dist/hu-HU.module.js.map +1 -0
  81. package/dist/import.mjs +20 -0
  82. package/dist/inputgroup_vars_css.main.js +86 -0
  83. package/dist/inputgroup_vars_css.main.js.map +1 -0
  84. package/dist/inputgroup_vars_css.mjs +88 -0
  85. package/dist/inputgroup_vars_css.module.js +88 -0
  86. package/dist/inputgroup_vars_css.module.js.map +1 -0
  87. package/dist/intlStrings.main.js +108 -0
  88. package/dist/intlStrings.main.js.map +1 -0
  89. package/dist/intlStrings.mjs +110 -0
  90. package/dist/intlStrings.module.js +110 -0
  91. package/dist/intlStrings.module.js.map +1 -0
  92. package/dist/it-IT.main.js +9 -0
  93. package/dist/it-IT.main.js.map +1 -0
  94. package/dist/it-IT.mjs +11 -0
  95. package/dist/it-IT.module.js +11 -0
  96. package/dist/it-IT.module.js.map +1 -0
  97. package/dist/ja-JP.main.js +9 -0
  98. package/dist/ja-JP.main.js.map +1 -0
  99. package/dist/ja-JP.mjs +11 -0
  100. package/dist/ja-JP.module.js +11 -0
  101. package/dist/ja-JP.module.js.map +1 -0
  102. package/dist/ko-KR.main.js +9 -0
  103. package/dist/ko-KR.main.js.map +1 -0
  104. package/dist/ko-KR.mjs +11 -0
  105. package/dist/ko-KR.module.js +11 -0
  106. package/dist/ko-KR.module.js.map +1 -0
  107. package/dist/lt-LT.main.js +9 -0
  108. package/dist/lt-LT.main.js.map +1 -0
  109. package/dist/lt-LT.mjs +11 -0
  110. package/dist/lt-LT.module.js +11 -0
  111. package/dist/lt-LT.module.js.map +1 -0
  112. package/dist/lv-LV.main.js +9 -0
  113. package/dist/lv-LV.main.js.map +1 -0
  114. package/dist/lv-LV.mjs +11 -0
  115. package/dist/lv-LV.module.js +11 -0
  116. package/dist/lv-LV.module.js.map +1 -0
  117. package/dist/main.js +14 -1149
  118. package/dist/main.js.map +1 -1
  119. package/dist/module.js +12 -1151
  120. package/dist/module.js.map +1 -1
  121. package/dist/nb-NO.main.js +9 -0
  122. package/dist/nb-NO.main.js.map +1 -0
  123. package/dist/nb-NO.mjs +11 -0
  124. package/dist/nb-NO.module.js +11 -0
  125. package/dist/nb-NO.module.js.map +1 -0
  126. package/dist/nl-NL.main.js +9 -0
  127. package/dist/nl-NL.main.js.map +1 -0
  128. package/dist/nl-NL.mjs +11 -0
  129. package/dist/nl-NL.module.js +11 -0
  130. package/dist/nl-NL.module.js.map +1 -0
  131. package/dist/pl-PL.main.js +9 -0
  132. package/dist/pl-PL.main.js.map +1 -0
  133. package/dist/pl-PL.mjs +11 -0
  134. package/dist/pl-PL.module.js +11 -0
  135. package/dist/pl-PL.module.js.map +1 -0
  136. package/dist/pt-BR.main.js +9 -0
  137. package/dist/pt-BR.main.js.map +1 -0
  138. package/dist/pt-BR.mjs +11 -0
  139. package/dist/pt-BR.module.js +11 -0
  140. package/dist/pt-BR.module.js.map +1 -0
  141. package/dist/pt-PT.main.js +9 -0
  142. package/dist/pt-PT.main.js.map +1 -0
  143. package/dist/pt-PT.mjs +11 -0
  144. package/dist/pt-PT.module.js +11 -0
  145. package/dist/pt-PT.module.js.map +1 -0
  146. package/dist/ro-RO.main.js +9 -0
  147. package/dist/ro-RO.main.js.map +1 -0
  148. package/dist/ro-RO.mjs +11 -0
  149. package/dist/ro-RO.module.js +11 -0
  150. package/dist/ro-RO.module.js.map +1 -0
  151. package/dist/ru-RU.main.js +9 -0
  152. package/dist/ru-RU.main.js.map +1 -0
  153. package/dist/ru-RU.mjs +11 -0
  154. package/dist/ru-RU.module.js +11 -0
  155. package/dist/ru-RU.module.js.map +1 -0
  156. package/dist/search_vars_css.main.js +53 -0
  157. package/dist/search_vars_css.main.js.map +1 -0
  158. package/dist/search_vars_css.mjs +55 -0
  159. package/dist/search_vars_css.module.js +55 -0
  160. package/dist/search_vars_css.module.js.map +1 -0
  161. package/dist/searchautocomplete.37ce4a26.css +55 -0
  162. package/dist/searchautocomplete.37ce4a26.css.map +1 -0
  163. package/dist/searchautocomplete_css.main.js +38 -0
  164. package/dist/searchautocomplete_css.main.js.map +1 -0
  165. package/dist/searchautocomplete_css.mjs +40 -0
  166. package/dist/searchautocomplete_css.module.js +40 -0
  167. package/dist/searchautocomplete_css.module.js.map +1 -0
  168. package/dist/sk-SK.main.js +9 -0
  169. package/dist/sk-SK.main.js.map +1 -0
  170. package/dist/sk-SK.mjs +11 -0
  171. package/dist/sk-SK.module.js +11 -0
  172. package/dist/sk-SK.module.js.map +1 -0
  173. package/dist/sl-SI.main.js +9 -0
  174. package/dist/sl-SI.main.js.map +1 -0
  175. package/dist/sl-SI.mjs +11 -0
  176. package/dist/sl-SI.module.js +11 -0
  177. package/dist/sl-SI.module.js.map +1 -0
  178. package/dist/sr-SP.main.js +9 -0
  179. package/dist/sr-SP.main.js.map +1 -0
  180. package/dist/sr-SP.mjs +11 -0
  181. package/dist/sr-SP.module.js +11 -0
  182. package/dist/sr-SP.module.js.map +1 -0
  183. package/dist/sv-SE.main.js +9 -0
  184. package/dist/sv-SE.main.js.map +1 -0
  185. package/dist/sv-SE.mjs +11 -0
  186. package/dist/sv-SE.module.js +11 -0
  187. package/dist/sv-SE.module.js.map +1 -0
  188. package/dist/textfield_vars_css.main.js +74 -0
  189. package/dist/textfield_vars_css.main.js.map +1 -0
  190. package/dist/textfield_vars_css.mjs +76 -0
  191. package/dist/textfield_vars_css.module.js +76 -0
  192. package/dist/textfield_vars_css.module.js.map +1 -0
  193. package/dist/tr-TR.main.js +9 -0
  194. package/dist/tr-TR.main.js.map +1 -0
  195. package/dist/tr-TR.mjs +11 -0
  196. package/dist/tr-TR.module.js +11 -0
  197. package/dist/tr-TR.module.js.map +1 -0
  198. package/dist/types.d.ts +5 -2
  199. package/dist/types.d.ts.map +1 -1
  200. package/dist/uk-UA.main.js +9 -0
  201. package/dist/uk-UA.main.js.map +1 -0
  202. package/dist/uk-UA.mjs +11 -0
  203. package/dist/uk-UA.module.js +11 -0
  204. package/dist/uk-UA.module.js.map +1 -0
  205. package/dist/vars.1905b5f6.css +649 -0
  206. package/dist/vars.1905b5f6.css.map +1 -0
  207. package/dist/vars.94a18fbf.css +223 -0
  208. package/dist/vars.94a18fbf.css.map +1 -0
  209. package/dist/vars.f9e74788.css +550 -0
  210. package/dist/vars.f9e74788.css.map +1 -0
  211. package/dist/zh-CN.main.js +9 -0
  212. package/dist/zh-CN.main.js.map +1 -0
  213. package/dist/zh-CN.mjs +11 -0
  214. package/dist/zh-CN.module.js +11 -0
  215. package/dist/zh-CN.module.js.map +1 -0
  216. package/dist/zh-TW.main.js +9 -0
  217. package/dist/zh-TW.main.js.map +1 -0
  218. package/dist/zh-TW.mjs +11 -0
  219. package/dist/zh-TW.module.js +11 -0
  220. package/dist/zh-TW.module.js.map +1 -0
  221. package/package.json +36 -31
  222. package/src/MobileSearchAutocomplete.tsx +220 -135
  223. package/src/SearchAutocomplete.tsx +107 -72
  224. package/src/searchautocomplete.css +11 -5
  225. package/LICENSE +0 -201
  226. package/dist/main.css +0 -1
@@ -10,21 +10,30 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  import {AriaButtonProps} from '@react-types/button';
13
- import {classNames, useFocusableRef, useIsMobileDevice, useResizeObserver, useUnwrapDOMRef} from '@react-spectrum/utils';
13
+ import {classNames, dimensionValue, useFocusableRef, useIsMobileDevice, useResizeObserver, useUnwrapDOMRef} from '@react-spectrum/utils';
14
14
  import {ClearButton} from '@react-spectrum/button';
15
- import {DismissButton, useOverlayPosition} from '@react-aria/overlays';
16
15
  import {DOMRefValue, FocusableRef} from '@react-types/shared';
17
16
  import {Field} from '@react-spectrum/label';
17
+ import {filterDOMProps, useLayoutEffect} from '@react-aria/utils';
18
18
  import {FocusRing} from '@react-aria/focus';
19
19
  // @ts-ignore
20
20
  import intlMessages from '../intl/*.json';
21
21
  import {ListBoxBase, useListBoxLayout} from '@react-spectrum/listbox';
22
22
  import Magnifier from '@spectrum-icons/ui/Magnifier';
23
23
  import {MobileSearchAutocomplete} from './MobileSearchAutocomplete';
24
- import {Placement} from '@react-types/overlays';
25
24
  import {Popover} from '@react-spectrum/overlays';
26
25
  import {ProgressCircle} from '@react-spectrum/progress';
27
- import React, {forwardRef, InputHTMLAttributes, RefObject, useCallback, useEffect, useRef, useState} from 'react';
26
+ import React, {
27
+ forwardRef,
28
+ InputHTMLAttributes,
29
+ ReactElement,
30
+ RefObject,
31
+ useCallback,
32
+ useEffect,
33
+ useRef,
34
+ useState
35
+ } from 'react';
36
+ import searchAutocompleteStyles from './searchautocomplete.css';
28
37
  import searchStyles from '@adobe/spectrum-css-temp/components/search/vars.css';
29
38
  import {SpectrumSearchAutocompleteProps} from '@react-types/autocomplete';
30
39
  import styles from '@adobe/spectrum-css-temp/components/inputgroup/vars.css';
@@ -32,13 +41,14 @@ import {TextFieldBase} from '@react-spectrum/textfield';
32
41
  import textfieldStyles from '@adobe/spectrum-css-temp/components/textfield/vars.css';
33
42
  import {useComboBoxState} from '@react-stately/combobox';
34
43
  import {useFilter, useLocalizedStringFormatter} from '@react-aria/i18n';
44
+ import {useFormProps} from '@react-spectrum/form';
35
45
  import {useHover} from '@react-aria/interactions';
36
- import {useLayoutEffect} from '@react-aria/utils';
37
46
  import {useProvider, useProviderProps} from '@react-spectrum/provider';
38
47
  import {useSearchAutocomplete} from '@react-aria/autocomplete';
39
48
 
40
49
  function SearchAutocomplete<T extends object>(props: SpectrumSearchAutocompleteProps<T>, ref: FocusableRef<HTMLElement>) {
41
50
  props = useProviderProps(props);
51
+ props = useFormProps(props);
42
52
 
43
53
  if (props.placeholder) {
44
54
  console.warn('Placeholders are deprecated due to accessibility issues. Please use help text instead.');
@@ -53,25 +63,28 @@ function SearchAutocomplete<T extends object>(props: SpectrumSearchAutocompleteP
53
63
  }
54
64
  }
55
65
 
56
- const SearchAutocompleteBase = React.forwardRef(function SearchAutocompleteBase<T extends object>(props: SpectrumSearchAutocompleteProps<T>, ref: FocusableRef<HTMLElement>) {
66
+ function _SearchAutocompleteBase<T extends object>(props: SpectrumSearchAutocompleteProps<T>, ref: FocusableRef<HTMLElement>) {
57
67
  props = useProviderProps(props);
58
68
 
59
69
  let {
60
70
  menuTrigger = 'input',
61
71
  shouldFlip = true,
62
72
  direction = 'bottom',
73
+ align = 'start',
63
74
  isQuiet,
75
+ menuWidth: customMenuWidth,
64
76
  loadingState,
65
77
  onLoadMore,
66
- onSubmit = () => {}
78
+ onSubmit = () => {},
79
+ validate
67
80
  } = props;
68
81
 
69
- let stringFormatter = useLocalizedStringFormatter(intlMessages);
82
+ let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/autocomplete');
70
83
  let isAsync = loadingState != null;
71
- let popoverRef = useRef<DOMRefValue<HTMLDivElement>>();
84
+ let popoverRef = useRef<DOMRefValue<HTMLDivElement>>(null);
72
85
  let unwrappedPopoverRef = useUnwrapDOMRef(popoverRef);
73
- let listBoxRef = useRef();
74
- let inputRef = useRef<HTMLInputElement>();
86
+ let listBoxRef = useRef(null);
87
+ let inputRef = useRef<HTMLInputElement>(null);
75
88
  let domRef = useFocusableRef(ref, inputRef);
76
89
 
77
90
  let {contains} = useFilter({sensitivity: 'base'});
@@ -83,15 +96,16 @@ const SearchAutocompleteBase = React.forwardRef(function SearchAutocompleteBase<
83
96
  allowsCustomValue: true,
84
97
  onSelectionChange: (key) => key !== null && onSubmit(null, key),
85
98
  selectedKey: undefined,
86
- defaultSelectedKey: undefined
99
+ defaultSelectedKey: undefined,
100
+ validate: useCallback(v => validate?.(v.inputValue), [validate])
87
101
  }
88
102
  );
89
- let layout = useListBoxLayout(state);
103
+ let layout = useListBoxLayout();
90
104
 
91
- let {inputProps, listBoxProps, labelProps, clearButtonProps} = useSearchAutocomplete(
105
+ let {inputProps, listBoxProps, labelProps, clearButtonProps, descriptionProps, errorMessageProps, isInvalid, validationErrors, validationDetails} = useSearchAutocomplete(
92
106
  {
93
107
  ...props,
94
- keyboardDelegate: layout,
108
+ layoutDelegate: layout,
95
109
  popoverRef: unwrappedPopoverRef,
96
110
  listBoxRef,
97
111
  inputRef,
@@ -100,18 +114,8 @@ const SearchAutocompleteBase = React.forwardRef(function SearchAutocompleteBase<
100
114
  state
101
115
  );
102
116
 
103
- let {overlayProps, placement, updatePosition} = useOverlayPosition({
104
- targetRef: inputRef,
105
- overlayRef: unwrappedPopoverRef,
106
- scrollRef: listBoxRef,
107
- placement: `${direction} end` as Placement,
108
- shouldFlip: shouldFlip,
109
- isOpen: state.isOpen,
110
- onClose: state.close
111
- });
112
-
113
117
  // Measure the width of the inputfield to inform the width of the menu (below).
114
- let [menuWidth, setMenuWidth] = useState(null);
118
+ let [menuWidth, setMenuWidth] = useState<number>(0);
115
119
  let {scale} = useProvider();
116
120
 
117
121
  let onResize = useCallback(() => {
@@ -128,77 +132,86 @@ const SearchAutocompleteBase = React.forwardRef(function SearchAutocompleteBase<
128
132
 
129
133
  useLayoutEffect(onResize, [scale, onResize]);
130
134
 
131
- // Update position once the ListBox has rendered. This ensures that
132
- // it flips properly when it doesn't fit in the available space.
133
- // TODO: add ResizeObserver to useOverlayPosition so we don't need this.
134
- useLayoutEffect(() => {
135
- if (state.isOpen) {
136
- requestAnimationFrame(() => {
137
- updatePosition();
138
- });
139
- }
140
- }, [state.isOpen, updatePosition]);
141
-
135
+ let width = isQuiet ? undefined : menuWidth;
142
136
  let style = {
143
- ...overlayProps.style,
144
- width: isQuiet ? null : menuWidth,
137
+ width: customMenuWidth ? dimensionValue(customMenuWidth) : width,
145
138
  minWidth: isQuiet ? `calc(${menuWidth}px + calc(2 * var(--spectrum-dropdown-quiet-offset)))` : menuWidth
146
139
  };
147
140
 
148
141
  return (
149
142
  <>
150
- <Field {...props} labelProps={labelProps} ref={domRef}>
143
+ <Field
144
+ {...props}
145
+ descriptionProps={descriptionProps}
146
+ errorMessageProps={errorMessageProps}
147
+ labelProps={labelProps}
148
+ isInvalid={isInvalid}
149
+ validationErrors={validationErrors}
150
+ validationDetails={validationDetails}
151
+ ref={domRef}>
151
152
  <SearchAutocompleteInput
152
153
  {...props}
153
154
  isOpen={state.isOpen}
154
155
  loadingState={loadingState}
155
156
  inputProps={inputProps}
156
157
  inputRef={inputRef}
157
- clearButtonProps={clearButtonProps} />
158
+ clearButtonProps={clearButtonProps}
159
+ validationState={props.validationState || (isInvalid ? 'invalid' : undefined)} />
158
160
  </Field>
159
161
  <Popover
160
- isOpen={state.isOpen}
162
+ state={state}
161
163
  UNSAFE_style={style}
162
164
  UNSAFE_className={classNames(styles, 'spectrum-InputGroup-popover', {'spectrum-InputGroup-popover--quiet': isQuiet})}
163
165
  ref={popoverRef}
164
- placement={placement}
166
+ triggerRef={inputRef}
167
+ placement={`${direction} ${align}`}
165
168
  hideArrow
166
169
  isNonModal
167
- isDismissable={false}>
170
+ shouldFlip={shouldFlip}>
168
171
  <ListBoxBase
169
172
  {...listBoxProps}
170
173
  ref={listBoxRef}
171
174
  disallowEmptySelection
172
- autoFocus={state.focusStrategy}
175
+ autoFocus={state.focusStrategy ?? undefined}
173
176
  shouldSelectOnPressUp
174
177
  focusOnPointerEnter
175
178
  layout={layout}
176
179
  state={state}
177
180
  shouldUseVirtualFocus
178
- isLoading={loadingState === 'loadingMore'}
181
+ isLoading={loadingState === 'loading' || loadingState === 'loadingMore'}
182
+ showLoadingSpinner={loadingState === 'loadingMore'}
179
183
  onLoadMore={onLoadMore}
180
184
  renderEmptyState={() => isAsync && (
181
- <span>
185
+ <span className={classNames(searchAutocompleteStyles, 'no-results')}>
182
186
  {stringFormatter.format('noResults')}
183
187
  </span>
184
188
  )} />
185
- <DismissButton onDismiss={() => state.close()} />
186
189
  </Popover>
187
190
  </>
188
191
  );
189
- });
192
+ }
193
+
194
+ let SearchAutocompleteBase = React.forwardRef(_SearchAutocompleteBase) as <T>(props: SpectrumSearchAutocompleteProps<T> & {ref?: FocusableRef<HTMLElement>}) => ReactElement;
195
+
190
196
 
191
- interface SearchAutocompleteInputProps extends SpectrumSearchAutocompleteProps<unknown> {
197
+ interface SearchAutocompleteInputProps<T> extends SpectrumSearchAutocompleteProps<T> {
192
198
  inputProps: InputHTMLAttributes<HTMLInputElement>,
193
- inputRef: RefObject<HTMLInputElement | HTMLTextAreaElement>,
199
+ inputRef: RefObject<HTMLInputElement | null>,
194
200
  style?: React.CSSProperties,
195
201
  className?: string,
196
202
  isOpen?: boolean,
197
203
  clearButtonProps: AriaButtonProps
198
204
  }
199
205
 
200
- const SearchAutocompleteInput = React.forwardRef(function SearchAutocompleteInput(props: SearchAutocompleteInputProps, ref: RefObject<HTMLElement>) {
206
+ // any type is because we don't want to call useObjectRef because this is an internal component and we know
207
+ // we are always passing an object ref
208
+ function _SearchAutocompleteInput<T>(props: SearchAutocompleteInputProps<T>, ref: any) {
209
+ let searchIcon = (
210
+ <Magnifier data-testid="searchicon" />
211
+ );
212
+
201
213
  let {
214
+ icon = searchIcon,
202
215
  isQuiet,
203
216
  isDisabled,
204
217
  isReadOnly,
@@ -214,8 +227,9 @@ const SearchAutocompleteInput = React.forwardRef(function SearchAutocompleteInpu
214
227
  clearButtonProps
215
228
  } = props;
216
229
  let {hoverProps, isHovered} = useHover({});
217
- let stringFormatter = useLocalizedStringFormatter(intlMessages);
218
- let timeout = useRef(null);
230
+ let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/autocomplete');
231
+ let domProps = filterDOMProps(props);
232
+ let timeout = useRef<ReturnType<typeof setTimeout> | null>(null);
219
233
  let [showLoading, setShowLoading] = useState(false);
220
234
 
221
235
  let loadingCircle = (
@@ -229,14 +243,14 @@ const SearchAutocompleteInput = React.forwardRef(function SearchAutocompleteInpu
229
243
  classNames(
230
244
  styles,
231
245
  'spectrum-InputGroup-input-circleLoader'
246
+ ),
247
+ classNames(
248
+ searchStyles,
249
+ 'spectrum-Search-circleLoader'
232
250
  )
233
251
  )} />
234
252
  );
235
253
 
236
- let searchIcon = (
237
- <Magnifier data-testid="searchicon" />
238
- );
239
-
240
254
  let clearButton = (
241
255
  <ClearButton
242
256
  {...clearButtonProps}
@@ -271,15 +285,17 @@ const SearchAutocompleteInput = React.forwardRef(function SearchAutocompleteInpu
271
285
  } else if (!isLoading) {
272
286
  // If loading is no longer happening, clear any timers and hide the loading circle
273
287
  setShowLoading(false);
274
- clearTimeout(timeout.current);
275
- timeout.current = null;
288
+ if (timeout.current != null) {
289
+ clearTimeout(timeout.current);
290
+ timeout.current = null;
291
+ }
276
292
  }
277
293
 
278
294
  lastInputValue.current = inputValue;
279
295
  }, [isLoading, showLoading, inputValue]);
280
296
 
281
297
  return (
282
- <FocusRing
298
+ (<FocusRing
283
299
  within
284
300
  isTextInput
285
301
  focusClass={classNames(styles, 'is-focused')}
@@ -287,7 +303,7 @@ const SearchAutocompleteInput = React.forwardRef(function SearchAutocompleteInpu
287
303
  autoFocus={autoFocus}>
288
304
  <div
289
305
  {...hoverProps}
290
- ref={ref as RefObject<HTMLDivElement>}
306
+ ref={ref as RefObject<HTMLDivElement | null>}
291
307
  style={style}
292
308
  className={
293
309
  classNames(
@@ -296,44 +312,63 @@ const SearchAutocompleteInput = React.forwardRef(function SearchAutocompleteInpu
296
312
  {
297
313
  'spectrum-InputGroup--quiet': isQuiet,
298
314
  'is-disabled': isDisabled,
299
- 'spectrum-InputGroup--invalid': validationState === 'invalid',
315
+ 'spectrum-InputGroup--invalid': validationState === 'invalid' && !isDisabled,
300
316
  'is-hovered': isHovered
301
317
  },
318
+ classNames(
319
+ searchAutocompleteStyles,
320
+ 'searchautocomplete'
321
+ ),
302
322
  className
303
323
  )
304
324
  }>
305
325
  <TextFieldBase
326
+ {...domProps}
306
327
  inputProps={inputProps}
307
328
  inputRef={inputRef}
308
329
  UNSAFE_className={
309
330
  classNames(
310
331
  searchStyles,
311
332
  'spectrum-Search',
333
+ 'spectrum-Search--loadable',
312
334
  'spectrum-Textfield',
313
335
  {
314
336
  'is-disabled': isDisabled,
315
337
  'is-quiet': isQuiet,
316
- 'spectrum-Search--invalid': validationState === 'invalid',
317
- 'spectrum-Search--valid': validationState === 'valid'
318
- }
338
+ 'spectrum-Search--invalid': validationState === 'invalid' && !isDisabled,
339
+ 'spectrum-Search--valid': validationState === 'valid' && !isDisabled
340
+ },
341
+ classNames(
342
+ styles,
343
+ 'spectrum-InputGroup-field'
344
+ )
319
345
  )
320
346
  }
321
347
  inputClassName={classNames(searchStyles, 'spectrum-Search-input')}
348
+ validationIconClassName={
349
+ classNames(
350
+ searchStyles,
351
+ 'spectrum-Search-validationIcon'
352
+ )
353
+ }
322
354
  isDisabled={isDisabled}
323
355
  isQuiet={isQuiet}
324
356
  validationState={validationState}
325
357
  isLoading={showLoading && (isOpen || menuTrigger === 'manual' || loadingState === 'loading')}
326
- loadingIndicator={loadingState != null && loadingCircle}
327
- icon={searchIcon}
328
- wrapperChildren={(inputValue !== '' && !isReadOnly) && clearButton} />
358
+ loadingIndicator={loadingState != null ? loadingCircle : undefined}
359
+ icon={icon}
360
+ wrapperChildren={(inputValue !== '' || loadingState === 'filtering' || validationState != null) && !isReadOnly ? clearButton : undefined}
361
+ disableFocusRing />
329
362
  </div>
330
- </FocusRing>
363
+ </FocusRing>)
331
364
  );
332
- });
365
+ }
366
+
367
+ let SearchAutocompleteInput = React.forwardRef(_SearchAutocompleteInput) as <T>(props: SearchAutocompleteInputProps<T> & {ref?: any}) => ReactElement;
333
368
 
334
369
 
335
370
  /**
336
371
  * A SearchAutocomplete is a searchfield that supports a dynamic list of suggestions.
337
372
  */
338
- let _SearchAutocomplete = forwardRef(SearchAutocomplete);
373
+ let _SearchAutocomplete = forwardRef(SearchAutocomplete) as <T>(props: SpectrumSearchAutocompleteProps<T> & {ref?: FocusableRef<HTMLElement>}) => ReactElement;
339
374
  export {_SearchAutocomplete as SearchAutocomplete};
@@ -20,7 +20,12 @@
20
20
  padding-inline-start: var(--spectrum-selectlist-option-padding);
21
21
  font-size: var(--spectrum-selectlist-option-text-size);
22
22
  font-weight: var(--spectrum-selectlist-option-text-font-weight);
23
- font-style: italic;
23
+ }
24
+
25
+ /* override .spectrum-InputGroup */
26
+ .searchautocomplete.searchautocomplete {
27
+ border-radius: var(--spectrum-search-border-radius);
28
+ --spectrum-focus-ring-border-radius: var(--spectrum-search-border-radius);
24
29
  }
25
30
 
26
31
  .mobile-searchautocomplete {
@@ -28,13 +33,14 @@
28
33
  }
29
34
 
30
35
  .mobile-input {
31
- white-space: nowrap;
32
- overflow: hidden;
33
- text-overflow: ellipsis;
36
+ display: flex;
37
+ align-items: center;
34
38
  }
35
39
 
36
40
  .mobile-value {
37
- vertical-align: middle;
41
+ white-space: nowrap;
42
+ overflow: hidden;
43
+ text-overflow: ellipsis;
38
44
  }
39
45
 
40
46
  .tray-dialog {
package/LICENSE DELETED
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright 2019 Adobe
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.