@react-spectrum/autocomplete 3.0.0-alpha.52 → 3.0.0-alpha.54

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/import.mjs +5 -3
  2. package/dist/main.js +7 -5
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +5 -3
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +4 -0
  7. package/package.json +14 -49
  8. package/src/index.ts +5 -3
  9. package/dist/MobileSearchAutocomplete.main.js +0 -449
  10. package/dist/MobileSearchAutocomplete.main.js.map +0 -1
  11. package/dist/MobileSearchAutocomplete.mjs +0 -444
  12. package/dist/MobileSearchAutocomplete.module.js +0 -444
  13. package/dist/MobileSearchAutocomplete.module.js.map +0 -1
  14. package/dist/SearchAutocomplete.main.js +0 -305
  15. package/dist/SearchAutocomplete.main.js.map +0 -1
  16. package/dist/SearchAutocomplete.mjs +0 -300
  17. package/dist/SearchAutocomplete.module.js +0 -300
  18. package/dist/SearchAutocomplete.module.js.map +0 -1
  19. package/dist/ar-AE.main.js +0 -9
  20. package/dist/ar-AE.main.js.map +0 -1
  21. package/dist/ar-AE.mjs +0 -11
  22. package/dist/ar-AE.module.js +0 -11
  23. package/dist/ar-AE.module.js.map +0 -1
  24. package/dist/autocomplete.02db68b2.css +0 -55
  25. package/dist/autocomplete.02db68b2.css.map +0 -1
  26. package/dist/autocomplete.102c5c14.css +0 -223
  27. package/dist/autocomplete.102c5c14.css.map +0 -1
  28. package/dist/autocomplete.30e64bfb.css +0 -550
  29. package/dist/autocomplete.30e64bfb.css.map +0 -1
  30. package/dist/autocomplete.c4adfff6.css +0 -649
  31. package/dist/autocomplete.c4adfff6.css.map +0 -1
  32. package/dist/bg-BG.main.js +0 -9
  33. package/dist/bg-BG.main.js.map +0 -1
  34. package/dist/bg-BG.mjs +0 -11
  35. package/dist/bg-BG.module.js +0 -11
  36. package/dist/bg-BG.module.js.map +0 -1
  37. package/dist/cs-CZ.main.js +0 -9
  38. package/dist/cs-CZ.main.js.map +0 -1
  39. package/dist/cs-CZ.mjs +0 -11
  40. package/dist/cs-CZ.module.js +0 -11
  41. package/dist/cs-CZ.module.js.map +0 -1
  42. package/dist/da-DK.main.js +0 -9
  43. package/dist/da-DK.main.js.map +0 -1
  44. package/dist/da-DK.mjs +0 -11
  45. package/dist/da-DK.module.js +0 -11
  46. package/dist/da-DK.module.js.map +0 -1
  47. package/dist/de-DE.main.js +0 -9
  48. package/dist/de-DE.main.js.map +0 -1
  49. package/dist/de-DE.mjs +0 -11
  50. package/dist/de-DE.module.js +0 -11
  51. package/dist/de-DE.module.js.map +0 -1
  52. package/dist/el-GR.main.js +0 -9
  53. package/dist/el-GR.main.js.map +0 -1
  54. package/dist/el-GR.mjs +0 -11
  55. package/dist/el-GR.module.js +0 -11
  56. package/dist/el-GR.module.js.map +0 -1
  57. package/dist/en-US.main.js +0 -9
  58. package/dist/en-US.main.js.map +0 -1
  59. package/dist/en-US.mjs +0 -11
  60. package/dist/en-US.module.js +0 -11
  61. package/dist/en-US.module.js.map +0 -1
  62. package/dist/es-ES.main.js +0 -9
  63. package/dist/es-ES.main.js.map +0 -1
  64. package/dist/es-ES.mjs +0 -11
  65. package/dist/es-ES.module.js +0 -11
  66. package/dist/es-ES.module.js.map +0 -1
  67. package/dist/et-EE.main.js +0 -9
  68. package/dist/et-EE.main.js.map +0 -1
  69. package/dist/et-EE.mjs +0 -11
  70. package/dist/et-EE.module.js +0 -11
  71. package/dist/et-EE.module.js.map +0 -1
  72. package/dist/fi-FI.main.js +0 -9
  73. package/dist/fi-FI.main.js.map +0 -1
  74. package/dist/fi-FI.mjs +0 -11
  75. package/dist/fi-FI.module.js +0 -11
  76. package/dist/fi-FI.module.js.map +0 -1
  77. package/dist/fr-FR.main.js +0 -9
  78. package/dist/fr-FR.main.js.map +0 -1
  79. package/dist/fr-FR.mjs +0 -11
  80. package/dist/fr-FR.module.js +0 -11
  81. package/dist/fr-FR.module.js.map +0 -1
  82. package/dist/he-IL.main.js +0 -9
  83. package/dist/he-IL.main.js.map +0 -1
  84. package/dist/he-IL.mjs +0 -11
  85. package/dist/he-IL.module.js +0 -11
  86. package/dist/he-IL.module.js.map +0 -1
  87. package/dist/hr-HR.main.js +0 -9
  88. package/dist/hr-HR.main.js.map +0 -1
  89. package/dist/hr-HR.mjs +0 -11
  90. package/dist/hr-HR.module.js +0 -11
  91. package/dist/hr-HR.module.js.map +0 -1
  92. package/dist/hu-HU.main.js +0 -9
  93. package/dist/hu-HU.main.js.map +0 -1
  94. package/dist/hu-HU.mjs +0 -11
  95. package/dist/hu-HU.module.js +0 -11
  96. package/dist/hu-HU.module.js.map +0 -1
  97. package/dist/inputgroup_vars_css.main.js +0 -86
  98. package/dist/inputgroup_vars_css.main.js.map +0 -1
  99. package/dist/inputgroup_vars_css.mjs +0 -88
  100. package/dist/inputgroup_vars_css.module.js +0 -88
  101. package/dist/inputgroup_vars_css.module.js.map +0 -1
  102. package/dist/intlStrings.main.js +0 -108
  103. package/dist/intlStrings.main.js.map +0 -1
  104. package/dist/intlStrings.mjs +0 -110
  105. package/dist/intlStrings.module.js +0 -110
  106. package/dist/intlStrings.module.js.map +0 -1
  107. package/dist/it-IT.main.js +0 -9
  108. package/dist/it-IT.main.js.map +0 -1
  109. package/dist/it-IT.mjs +0 -11
  110. package/dist/it-IT.module.js +0 -11
  111. package/dist/it-IT.module.js.map +0 -1
  112. package/dist/ja-JP.main.js +0 -9
  113. package/dist/ja-JP.main.js.map +0 -1
  114. package/dist/ja-JP.mjs +0 -11
  115. package/dist/ja-JP.module.js +0 -11
  116. package/dist/ja-JP.module.js.map +0 -1
  117. package/dist/ko-KR.main.js +0 -9
  118. package/dist/ko-KR.main.js.map +0 -1
  119. package/dist/ko-KR.mjs +0 -11
  120. package/dist/ko-KR.module.js +0 -11
  121. package/dist/ko-KR.module.js.map +0 -1
  122. package/dist/lt-LT.main.js +0 -9
  123. package/dist/lt-LT.main.js.map +0 -1
  124. package/dist/lt-LT.mjs +0 -11
  125. package/dist/lt-LT.module.js +0 -11
  126. package/dist/lt-LT.module.js.map +0 -1
  127. package/dist/lv-LV.main.js +0 -9
  128. package/dist/lv-LV.main.js.map +0 -1
  129. package/dist/lv-LV.mjs +0 -11
  130. package/dist/lv-LV.module.js +0 -11
  131. package/dist/lv-LV.module.js.map +0 -1
  132. package/dist/nb-NO.main.js +0 -9
  133. package/dist/nb-NO.main.js.map +0 -1
  134. package/dist/nb-NO.mjs +0 -11
  135. package/dist/nb-NO.module.js +0 -11
  136. package/dist/nb-NO.module.js.map +0 -1
  137. package/dist/nl-NL.main.js +0 -9
  138. package/dist/nl-NL.main.js.map +0 -1
  139. package/dist/nl-NL.mjs +0 -11
  140. package/dist/nl-NL.module.js +0 -11
  141. package/dist/nl-NL.module.js.map +0 -1
  142. package/dist/pl-PL.main.js +0 -9
  143. package/dist/pl-PL.main.js.map +0 -1
  144. package/dist/pl-PL.mjs +0 -11
  145. package/dist/pl-PL.module.js +0 -11
  146. package/dist/pl-PL.module.js.map +0 -1
  147. package/dist/pt-BR.main.js +0 -9
  148. package/dist/pt-BR.main.js.map +0 -1
  149. package/dist/pt-BR.mjs +0 -11
  150. package/dist/pt-BR.module.js +0 -11
  151. package/dist/pt-BR.module.js.map +0 -1
  152. package/dist/pt-PT.main.js +0 -9
  153. package/dist/pt-PT.main.js.map +0 -1
  154. package/dist/pt-PT.mjs +0 -11
  155. package/dist/pt-PT.module.js +0 -11
  156. package/dist/pt-PT.module.js.map +0 -1
  157. package/dist/ro-RO.main.js +0 -9
  158. package/dist/ro-RO.main.js.map +0 -1
  159. package/dist/ro-RO.mjs +0 -11
  160. package/dist/ro-RO.module.js +0 -11
  161. package/dist/ro-RO.module.js.map +0 -1
  162. package/dist/ru-RU.main.js +0 -9
  163. package/dist/ru-RU.main.js.map +0 -1
  164. package/dist/ru-RU.mjs +0 -11
  165. package/dist/ru-RU.module.js +0 -11
  166. package/dist/ru-RU.module.js.map +0 -1
  167. package/dist/search_vars_css.main.js +0 -53
  168. package/dist/search_vars_css.main.js.map +0 -1
  169. package/dist/search_vars_css.mjs +0 -55
  170. package/dist/search_vars_css.module.js +0 -55
  171. package/dist/search_vars_css.module.js.map +0 -1
  172. package/dist/searchautocomplete_css.main.js +0 -38
  173. package/dist/searchautocomplete_css.main.js.map +0 -1
  174. package/dist/searchautocomplete_css.mjs +0 -40
  175. package/dist/searchautocomplete_css.module.js +0 -40
  176. package/dist/searchautocomplete_css.module.js.map +0 -1
  177. package/dist/sk-SK.main.js +0 -9
  178. package/dist/sk-SK.main.js.map +0 -1
  179. package/dist/sk-SK.mjs +0 -11
  180. package/dist/sk-SK.module.js +0 -11
  181. package/dist/sk-SK.module.js.map +0 -1
  182. package/dist/sl-SI.main.js +0 -9
  183. package/dist/sl-SI.main.js.map +0 -1
  184. package/dist/sl-SI.mjs +0 -11
  185. package/dist/sl-SI.module.js +0 -11
  186. package/dist/sl-SI.module.js.map +0 -1
  187. package/dist/sr-SP.main.js +0 -9
  188. package/dist/sr-SP.main.js.map +0 -1
  189. package/dist/sr-SP.mjs +0 -11
  190. package/dist/sr-SP.module.js +0 -11
  191. package/dist/sr-SP.module.js.map +0 -1
  192. package/dist/sv-SE.main.js +0 -9
  193. package/dist/sv-SE.main.js.map +0 -1
  194. package/dist/sv-SE.mjs +0 -11
  195. package/dist/sv-SE.module.js +0 -11
  196. package/dist/sv-SE.module.js.map +0 -1
  197. package/dist/textfield_vars_css.main.js +0 -74
  198. package/dist/textfield_vars_css.main.js.map +0 -1
  199. package/dist/textfield_vars_css.mjs +0 -76
  200. package/dist/textfield_vars_css.module.js +0 -76
  201. package/dist/textfield_vars_css.module.js.map +0 -1
  202. package/dist/tr-TR.main.js +0 -9
  203. package/dist/tr-TR.main.js.map +0 -1
  204. package/dist/tr-TR.mjs +0 -11
  205. package/dist/tr-TR.module.js +0 -11
  206. package/dist/tr-TR.module.js.map +0 -1
  207. package/dist/types.d.ts +0 -13
  208. package/dist/types.d.ts.map +0 -1
  209. package/dist/uk-UA.main.js +0 -9
  210. package/dist/uk-UA.main.js.map +0 -1
  211. package/dist/uk-UA.mjs +0 -11
  212. package/dist/uk-UA.module.js +0 -11
  213. package/dist/uk-UA.module.js.map +0 -1
  214. package/dist/zh-CN.main.js +0 -9
  215. package/dist/zh-CN.main.js.map +0 -1
  216. package/dist/zh-CN.mjs +0 -11
  217. package/dist/zh-CN.module.js +0 -11
  218. package/dist/zh-CN.module.js.map +0 -1
  219. package/dist/zh-TW.main.js +0 -9
  220. package/dist/zh-TW.main.js.map +0 -1
  221. package/dist/zh-TW.mjs +0 -11
  222. package/dist/zh-TW.module.js +0 -11
  223. package/dist/zh-TW.module.js.map +0 -1
  224. package/src/MobileSearchAutocomplete.tsx +0 -632
  225. package/src/SearchAutocomplete.tsx +0 -382
  226. package/src/searchautocomplete.css +0 -71
@@ -1,382 +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
- import {AriaButtonProps} from '@react-types/button';
13
- import {classNames, dimensionValue, useFocusableRef, useIsMobileDevice, useResizeObserver, useUnwrapDOMRef} from '@react-spectrum/utils';
14
- import {ClearButton} from '@react-spectrum/button';
15
- import {DOMRefValue, FocusableRef} from '@react-types/shared';
16
- import {Field} from '@react-spectrum/label';
17
- import {filterDOMProps, useLayoutEffect} from '@react-aria/utils';
18
- import {FocusRing} from '@react-aria/focus';
19
- // @ts-ignore
20
- import intlMessages from '../intl/*.json';
21
- import {ListBoxBase, useListBoxLayout} from '@react-spectrum/listbox';
22
- import Magnifier from '@spectrum-icons/ui/Magnifier';
23
- import {MobileSearchAutocomplete} from './MobileSearchAutocomplete';
24
- import {Popover} from '@react-spectrum/overlays';
25
- import {ProgressCircle} from '@react-spectrum/progress';
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';
37
- import searchStyles from '@adobe/spectrum-css-temp/components/search/vars.css';
38
- import {SpectrumSearchAutocompleteProps} from '@react-types/autocomplete';
39
- import styles from '@adobe/spectrum-css-temp/components/inputgroup/vars.css';
40
- import {TextFieldBase} from '@react-spectrum/textfield';
41
- import textfieldStyles from '@adobe/spectrum-css-temp/components/textfield/vars.css';
42
- import {useComboBoxState} from '@react-stately/combobox';
43
- import {useFilter, useLocalizedStringFormatter} from '@react-aria/i18n';
44
- import {useFormProps} from '@react-spectrum/form';
45
- import {useHover} from '@react-aria/interactions';
46
- import {useProvider, useProviderProps} from '@react-spectrum/provider';
47
- import {useSearchAutocomplete} from '@react-aria/autocomplete';
48
-
49
- function SearchAutocomplete<T extends object>(props: SpectrumSearchAutocompleteProps<T>, ref: FocusableRef<HTMLElement>) {
50
- props = useProviderProps(props);
51
- props = useFormProps(props);
52
-
53
- let hasWarned = useRef(false);
54
- useEffect(() => {
55
- if (props.placeholder && !hasWarned.current && process.env.NODE_ENV !== 'production') {
56
- console.warn('Placeholders are deprecated due to accessibility issues. Please use help text instead.');
57
- hasWarned.current = true;
58
- }
59
- }, [props.placeholder]);
60
-
61
- let isMobile = useIsMobileDevice();
62
- if (isMobile) {
63
- // menuTrigger=focus/manual don't apply to mobile searchwithin
64
- return <MobileSearchAutocomplete {...props} menuTrigger="input" ref={ref} />;
65
- } else {
66
- return <SearchAutocompleteBase {...props} ref={ref} />;
67
- }
68
- }
69
-
70
- function ForwardSearchAutocompleteBase<T extends object>(props: SpectrumSearchAutocompleteProps<T>, ref: FocusableRef<HTMLElement>) {
71
- props = useProviderProps(props);
72
-
73
- let {
74
- menuTrigger = 'input',
75
- shouldFlip = true,
76
- direction = 'bottom',
77
- align = 'start',
78
- isQuiet,
79
- menuWidth: customMenuWidth,
80
- loadingState,
81
- onLoadMore,
82
- onSubmit = () => {},
83
- validate
84
- } = props;
85
-
86
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/autocomplete');
87
- let isAsync = loadingState != null;
88
- let popoverRef = useRef<DOMRefValue<HTMLDivElement>>(null);
89
- let unwrappedPopoverRef = useUnwrapDOMRef(popoverRef);
90
- let listBoxRef = useRef(null);
91
- let inputRef = useRef<HTMLInputElement>(null);
92
- let domRef = useFocusableRef(ref, inputRef);
93
-
94
- let {contains} = useFilter({sensitivity: 'base'});
95
- let state = useComboBoxState(
96
- {
97
- ...props,
98
- defaultFilter: contains,
99
- allowsEmptyCollection: isAsync,
100
- allowsCustomValue: true,
101
- onSelectionChange: (key) => key !== null && onSubmit(null, key),
102
- selectedKey: undefined,
103
- defaultSelectedKey: undefined,
104
- validate: useCallback(v => validate?.(v.inputValue), [validate])
105
- }
106
- );
107
- let layout = useListBoxLayout();
108
-
109
- let {inputProps, listBoxProps, labelProps, clearButtonProps, descriptionProps, errorMessageProps, isInvalid, validationErrors, validationDetails} = useSearchAutocomplete(
110
- {
111
- ...props,
112
- layoutDelegate: layout,
113
- popoverRef: unwrappedPopoverRef,
114
- listBoxRef,
115
- inputRef,
116
- menuTrigger
117
- },
118
- state
119
- );
120
-
121
- // Measure the width of the inputfield to inform the width of the menu (below).
122
- let [menuWidth, setMenuWidth] = useState<number>(0);
123
- let {scale} = useProvider();
124
-
125
- let onResize = useCallback(() => {
126
- if (inputRef.current) {
127
- let inputWidth = inputRef.current.offsetWidth;
128
- setMenuWidth(inputWidth);
129
- }
130
- }, [inputRef, setMenuWidth]);
131
-
132
- useResizeObserver({
133
- ref: domRef,
134
- onResize: onResize
135
- });
136
-
137
- useLayoutEffect(onResize, [scale, onResize]);
138
-
139
- let width = isQuiet ? undefined : menuWidth;
140
- let style = {
141
- width: customMenuWidth ? dimensionValue(customMenuWidth) : width,
142
- minWidth: isQuiet ? `calc(${menuWidth}px + calc(2 * var(--spectrum-dropdown-quiet-offset)))` : menuWidth
143
- };
144
-
145
- return (
146
- <>
147
- <Field
148
- {...props}
149
- descriptionProps={descriptionProps}
150
- errorMessageProps={errorMessageProps}
151
- labelProps={labelProps}
152
- isInvalid={isInvalid}
153
- validationErrors={validationErrors}
154
- validationDetails={validationDetails}
155
- ref={domRef}>
156
- <SearchAutocompleteInput
157
- {...props}
158
- isOpen={state.isOpen}
159
- loadingState={loadingState}
160
- inputProps={inputProps}
161
- inputRef={inputRef}
162
- clearButtonProps={clearButtonProps}
163
- validationState={props.validationState || (isInvalid ? 'invalid' : undefined)} />
164
- </Field>
165
- <Popover
166
- state={state}
167
- UNSAFE_style={style}
168
- UNSAFE_className={classNames(styles, 'spectrum-InputGroup-popover', {'spectrum-InputGroup-popover--quiet': isQuiet})}
169
- ref={popoverRef}
170
- triggerRef={inputRef}
171
- placement={`${direction} ${align}`}
172
- hideArrow
173
- isNonModal
174
- shouldFlip={shouldFlip}>
175
- <ListBoxBase
176
- {...listBoxProps}
177
- ref={listBoxRef}
178
- disallowEmptySelection
179
- autoFocus={state.focusStrategy ?? undefined}
180
- shouldSelectOnPressUp
181
- focusOnPointerEnter
182
- layout={layout}
183
- state={state}
184
- shouldUseVirtualFocus
185
- isLoading={loadingState === 'loading' || loadingState === 'loadingMore'}
186
- showLoadingSpinner={loadingState === 'loadingMore'}
187
- onLoadMore={onLoadMore}
188
- renderEmptyState={() => isAsync && (
189
- <span className={classNames(searchAutocompleteStyles, 'no-results')}>
190
- {stringFormatter.format('noResults')}
191
- </span>
192
- )} />
193
- </Popover>
194
- </>
195
- );
196
- }
197
-
198
- let SearchAutocompleteBase = React.forwardRef(ForwardSearchAutocompleteBase) as <T>(props: SpectrumSearchAutocompleteProps<T> & {ref?: FocusableRef<HTMLElement>}) => ReactElement;
199
-
200
-
201
- interface SearchAutocompleteInputProps<T> extends SpectrumSearchAutocompleteProps<T> {
202
- inputProps: InputHTMLAttributes<HTMLInputElement>,
203
- inputRef: RefObject<HTMLInputElement | null>,
204
- style?: React.CSSProperties,
205
- className?: string,
206
- isOpen?: boolean,
207
- clearButtonProps: AriaButtonProps
208
- }
209
-
210
- // any type is because we don't want to call useObjectRef because this is an internal component and we know
211
- // we are always passing an object ref
212
- function ForwardSearchAutocompleteInput<T>(props: SearchAutocompleteInputProps<T>, ref: any) {
213
- let searchIcon = (
214
- <Magnifier data-testid="searchicon" />
215
- );
216
-
217
- let {
218
- icon = searchIcon,
219
- isQuiet,
220
- isDisabled,
221
- isReadOnly,
222
- validationState,
223
- inputProps,
224
- inputRef,
225
- autoFocus,
226
- style,
227
- className,
228
- loadingState,
229
- isOpen,
230
- menuTrigger,
231
- clearButtonProps
232
- } = props;
233
- let {hoverProps, isHovered} = useHover({});
234
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/autocomplete');
235
- let domProps = filterDOMProps(props);
236
- let timeout = useRef<ReturnType<typeof setTimeout> | null>(null);
237
- let [showLoading, setShowLoading] = useState(false);
238
-
239
- let loadingCircle = (
240
- <ProgressCircle
241
- aria-label={stringFormatter.format('loading')}
242
- size="S"
243
- isIndeterminate
244
- UNSAFE_className={classNames(
245
- textfieldStyles,
246
- 'spectrum-Textfield-circleLoader',
247
- classNames(
248
- styles,
249
- 'spectrum-InputGroup-input-circleLoader'
250
- ),
251
- classNames(
252
- searchStyles,
253
- 'spectrum-Search-circleLoader'
254
- )
255
- )} />
256
- );
257
-
258
- let clearButton = (
259
- <ClearButton
260
- {...clearButtonProps}
261
- preventFocus
262
- UNSAFE_className={
263
- classNames(
264
- searchStyles,
265
- 'spectrum-ClearButton'
266
- )
267
- }
268
- isDisabled={isDisabled} />
269
- );
270
-
271
- let isLoading = loadingState === 'loading' || loadingState === 'filtering';
272
- let inputValue = inputProps.value;
273
- let lastInputValue = useRef(inputValue);
274
- useEffect(() => {
275
- if (isLoading && !showLoading) {
276
- if (timeout.current === null) {
277
- timeout.current = setTimeout(() => {
278
- setShowLoading(true);
279
- }, 500);
280
- }
281
-
282
- // If user is typing, clear the timer and restart since it is a new request
283
- if (inputValue !== lastInputValue.current) {
284
- clearTimeout(timeout.current);
285
- timeout.current = setTimeout(() => {
286
- setShowLoading(true);
287
- }, 500);
288
- }
289
- } else if (!isLoading) {
290
- // If loading is no longer happening, clear any timers and hide the loading circle
291
- if (timeout.current != null) {
292
- clearTimeout(timeout.current);
293
- timeout.current = null;
294
- }
295
- }
296
-
297
- lastInputValue.current = inputValue;
298
- }, [isLoading, showLoading, inputValue]);
299
- let [prevIsLoading, setPrevIsLoading] = useState(isLoading);
300
- if (prevIsLoading !== isLoading && !isLoading) {
301
- setShowLoading(false);
302
- setPrevIsLoading(isLoading);
303
- }
304
-
305
- return (
306
- (<FocusRing
307
- within
308
- isTextInput
309
- focusClass={classNames(styles, 'is-focused')}
310
- focusRingClass={classNames(styles, 'focus-ring')}
311
- autoFocus={autoFocus}>
312
- <div
313
- {...hoverProps}
314
- ref={ref as RefObject<HTMLDivElement | null>}
315
- style={style}
316
- className={
317
- classNames(
318
- styles,
319
- 'spectrum-InputGroup',
320
- {
321
- 'spectrum-InputGroup--quiet': isQuiet,
322
- 'is-disabled': isDisabled,
323
- 'spectrum-InputGroup--invalid': validationState === 'invalid' && !isDisabled,
324
- 'is-hovered': isHovered
325
- },
326
- classNames(
327
- searchAutocompleteStyles,
328
- 'searchautocomplete'
329
- ),
330
- className
331
- )
332
- }>
333
- <TextFieldBase
334
- {...domProps}
335
- inputProps={inputProps}
336
- inputRef={inputRef}
337
- UNSAFE_className={
338
- classNames(
339
- searchStyles,
340
- 'spectrum-Search',
341
- 'spectrum-Search--loadable',
342
- 'spectrum-Textfield',
343
- {
344
- 'is-disabled': isDisabled,
345
- 'is-quiet': isQuiet,
346
- 'spectrum-Search--invalid': validationState === 'invalid' && !isDisabled,
347
- 'spectrum-Search--valid': validationState === 'valid' && !isDisabled
348
- },
349
- classNames(
350
- styles,
351
- 'spectrum-InputGroup-field'
352
- )
353
- )
354
- }
355
- inputClassName={classNames(searchStyles, 'spectrum-Search-input')}
356
- validationIconClassName={
357
- classNames(
358
- searchStyles,
359
- 'spectrum-Search-validationIcon'
360
- )
361
- }
362
- isDisabled={isDisabled}
363
- isQuiet={isQuiet}
364
- validationState={validationState}
365
- isLoading={showLoading && (isOpen || menuTrigger === 'manual' || loadingState === 'loading')}
366
- loadingIndicator={loadingState != null ? loadingCircle : undefined}
367
- icon={icon}
368
- wrapperChildren={(inputValue !== '' || loadingState === 'filtering' || validationState != null) && !isReadOnly ? clearButton : undefined}
369
- disableFocusRing />
370
- </div>
371
- </FocusRing>)
372
- );
373
- }
374
-
375
- let SearchAutocompleteInput = React.forwardRef(ForwardSearchAutocompleteInput) as <T>(props: SearchAutocompleteInputProps<T> & {ref?: any}) => ReactElement;
376
-
377
-
378
- /**
379
- * A SearchAutocomplete is a searchfield that supports a dynamic list of suggestions.
380
- */
381
- let ForwardSearchAutocomplete = forwardRef(SearchAutocomplete) as <T>(props: SpectrumSearchAutocompleteProps<T> & {ref?: FocusableRef<HTMLElement>}) => ReactElement;
382
- export {ForwardSearchAutocomplete as SearchAutocomplete};
@@ -1,71 +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
- .no-results {
14
- display: block;
15
- /*
16
- Renamed from padding-y to padding-height to fix docs issue where fallback var replaced this value
17
- (due to old spectrum-css postcss-custom-properties-custom-mapping plugin).
18
- */
19
- padding-top: var(--spectrum-selectlist-option-padding-height);
20
- padding-inline-start: var(--spectrum-selectlist-option-padding);
21
- font-size: var(--spectrum-selectlist-option-text-size);
22
- font-weight: var(--spectrum-selectlist-option-text-font-weight);
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);
29
- }
30
-
31
- .mobile-searchautocomplete {
32
- outline: none;
33
- }
34
-
35
- .mobile-input {
36
- display: flex;
37
- align-items: center;
38
- }
39
-
40
- .mobile-value {
41
- white-space: nowrap;
42
- overflow: hidden;
43
- text-overflow: ellipsis;
44
- }
45
-
46
- .tray-dialog {
47
- display: flex;
48
- flex-direction: column;
49
- height: 100%;
50
- outline: none;
51
- }
52
-
53
- .tray-textfield {
54
- margin: var(--spectrum-global-dimension-size-150);
55
- margin-bottom: var(--spectrum-global-dimension-size-50);
56
- flex-shrink: 0;
57
- width: initial !important;
58
-
59
- &.has-label {
60
- margin-top: var(--spectrum-global-dimension-size-50);
61
- }
62
-
63
- .tray-textfield-input {
64
- padding-inline-start: var(--spectrum-textfield-padding-x);
65
- }
66
- }
67
-
68
- .tray-listbox {
69
- width: 100%;
70
- flex: 1;
71
- }