@react-spectrum/autocomplete 3.0.0-alpha.53 → 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.
- package/dist/import.mjs +5 -3
- package/dist/main.js +7 -5
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -3
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +4 -0
- package/package.json +14 -49
- package/src/index.ts +5 -3
- package/dist/MobileSearchAutocomplete.main.js +0 -449
- package/dist/MobileSearchAutocomplete.main.js.map +0 -1
- package/dist/MobileSearchAutocomplete.mjs +0 -444
- package/dist/MobileSearchAutocomplete.module.js +0 -444
- package/dist/MobileSearchAutocomplete.module.js.map +0 -1
- package/dist/SearchAutocomplete.main.js +0 -305
- package/dist/SearchAutocomplete.main.js.map +0 -1
- package/dist/SearchAutocomplete.mjs +0 -300
- package/dist/SearchAutocomplete.module.js +0 -300
- package/dist/SearchAutocomplete.module.js.map +0 -1
- package/dist/ar-AE.main.js +0 -9
- package/dist/ar-AE.main.js.map +0 -1
- package/dist/ar-AE.mjs +0 -11
- package/dist/ar-AE.module.js +0 -11
- package/dist/ar-AE.module.js.map +0 -1
- package/dist/autocomplete.02db68b2.css +0 -55
- package/dist/autocomplete.02db68b2.css.map +0 -1
- package/dist/autocomplete.102c5c14.css +0 -223
- package/dist/autocomplete.102c5c14.css.map +0 -1
- package/dist/autocomplete.30e64bfb.css +0 -550
- package/dist/autocomplete.30e64bfb.css.map +0 -1
- package/dist/autocomplete.c4adfff6.css +0 -649
- package/dist/autocomplete.c4adfff6.css.map +0 -1
- package/dist/bg-BG.main.js +0 -9
- package/dist/bg-BG.main.js.map +0 -1
- package/dist/bg-BG.mjs +0 -11
- package/dist/bg-BG.module.js +0 -11
- package/dist/bg-BG.module.js.map +0 -1
- package/dist/cs-CZ.main.js +0 -9
- package/dist/cs-CZ.main.js.map +0 -1
- package/dist/cs-CZ.mjs +0 -11
- package/dist/cs-CZ.module.js +0 -11
- package/dist/cs-CZ.module.js.map +0 -1
- package/dist/da-DK.main.js +0 -9
- package/dist/da-DK.main.js.map +0 -1
- package/dist/da-DK.mjs +0 -11
- package/dist/da-DK.module.js +0 -11
- package/dist/da-DK.module.js.map +0 -1
- package/dist/de-DE.main.js +0 -9
- package/dist/de-DE.main.js.map +0 -1
- package/dist/de-DE.mjs +0 -11
- package/dist/de-DE.module.js +0 -11
- package/dist/de-DE.module.js.map +0 -1
- package/dist/el-GR.main.js +0 -9
- package/dist/el-GR.main.js.map +0 -1
- package/dist/el-GR.mjs +0 -11
- package/dist/el-GR.module.js +0 -11
- package/dist/el-GR.module.js.map +0 -1
- package/dist/en-US.main.js +0 -9
- package/dist/en-US.main.js.map +0 -1
- package/dist/en-US.mjs +0 -11
- package/dist/en-US.module.js +0 -11
- package/dist/en-US.module.js.map +0 -1
- package/dist/es-ES.main.js +0 -9
- package/dist/es-ES.main.js.map +0 -1
- package/dist/es-ES.mjs +0 -11
- package/dist/es-ES.module.js +0 -11
- package/dist/es-ES.module.js.map +0 -1
- package/dist/et-EE.main.js +0 -9
- package/dist/et-EE.main.js.map +0 -1
- package/dist/et-EE.mjs +0 -11
- package/dist/et-EE.module.js +0 -11
- package/dist/et-EE.module.js.map +0 -1
- package/dist/fi-FI.main.js +0 -9
- package/dist/fi-FI.main.js.map +0 -1
- package/dist/fi-FI.mjs +0 -11
- package/dist/fi-FI.module.js +0 -11
- package/dist/fi-FI.module.js.map +0 -1
- package/dist/fr-FR.main.js +0 -9
- package/dist/fr-FR.main.js.map +0 -1
- package/dist/fr-FR.mjs +0 -11
- package/dist/fr-FR.module.js +0 -11
- package/dist/fr-FR.module.js.map +0 -1
- package/dist/he-IL.main.js +0 -9
- package/dist/he-IL.main.js.map +0 -1
- package/dist/he-IL.mjs +0 -11
- package/dist/he-IL.module.js +0 -11
- package/dist/he-IL.module.js.map +0 -1
- package/dist/hr-HR.main.js +0 -9
- package/dist/hr-HR.main.js.map +0 -1
- package/dist/hr-HR.mjs +0 -11
- package/dist/hr-HR.module.js +0 -11
- package/dist/hr-HR.module.js.map +0 -1
- package/dist/hu-HU.main.js +0 -9
- package/dist/hu-HU.main.js.map +0 -1
- package/dist/hu-HU.mjs +0 -11
- package/dist/hu-HU.module.js +0 -11
- package/dist/hu-HU.module.js.map +0 -1
- package/dist/inputgroup_vars_css.main.js +0 -86
- package/dist/inputgroup_vars_css.main.js.map +0 -1
- package/dist/inputgroup_vars_css.mjs +0 -88
- package/dist/inputgroup_vars_css.module.js +0 -88
- package/dist/inputgroup_vars_css.module.js.map +0 -1
- package/dist/intlStrings.main.js +0 -108
- package/dist/intlStrings.main.js.map +0 -1
- package/dist/intlStrings.mjs +0 -110
- package/dist/intlStrings.module.js +0 -110
- package/dist/intlStrings.module.js.map +0 -1
- package/dist/it-IT.main.js +0 -9
- package/dist/it-IT.main.js.map +0 -1
- package/dist/it-IT.mjs +0 -11
- package/dist/it-IT.module.js +0 -11
- package/dist/it-IT.module.js.map +0 -1
- package/dist/ja-JP.main.js +0 -9
- package/dist/ja-JP.main.js.map +0 -1
- package/dist/ja-JP.mjs +0 -11
- package/dist/ja-JP.module.js +0 -11
- package/dist/ja-JP.module.js.map +0 -1
- package/dist/ko-KR.main.js +0 -9
- package/dist/ko-KR.main.js.map +0 -1
- package/dist/ko-KR.mjs +0 -11
- package/dist/ko-KR.module.js +0 -11
- package/dist/ko-KR.module.js.map +0 -1
- package/dist/lt-LT.main.js +0 -9
- package/dist/lt-LT.main.js.map +0 -1
- package/dist/lt-LT.mjs +0 -11
- package/dist/lt-LT.module.js +0 -11
- package/dist/lt-LT.module.js.map +0 -1
- package/dist/lv-LV.main.js +0 -9
- package/dist/lv-LV.main.js.map +0 -1
- package/dist/lv-LV.mjs +0 -11
- package/dist/lv-LV.module.js +0 -11
- package/dist/lv-LV.module.js.map +0 -1
- package/dist/nb-NO.main.js +0 -9
- package/dist/nb-NO.main.js.map +0 -1
- package/dist/nb-NO.mjs +0 -11
- package/dist/nb-NO.module.js +0 -11
- package/dist/nb-NO.module.js.map +0 -1
- package/dist/nl-NL.main.js +0 -9
- package/dist/nl-NL.main.js.map +0 -1
- package/dist/nl-NL.mjs +0 -11
- package/dist/nl-NL.module.js +0 -11
- package/dist/nl-NL.module.js.map +0 -1
- package/dist/pl-PL.main.js +0 -9
- package/dist/pl-PL.main.js.map +0 -1
- package/dist/pl-PL.mjs +0 -11
- package/dist/pl-PL.module.js +0 -11
- package/dist/pl-PL.module.js.map +0 -1
- package/dist/pt-BR.main.js +0 -9
- package/dist/pt-BR.main.js.map +0 -1
- package/dist/pt-BR.mjs +0 -11
- package/dist/pt-BR.module.js +0 -11
- package/dist/pt-BR.module.js.map +0 -1
- package/dist/pt-PT.main.js +0 -9
- package/dist/pt-PT.main.js.map +0 -1
- package/dist/pt-PT.mjs +0 -11
- package/dist/pt-PT.module.js +0 -11
- package/dist/pt-PT.module.js.map +0 -1
- package/dist/ro-RO.main.js +0 -9
- package/dist/ro-RO.main.js.map +0 -1
- package/dist/ro-RO.mjs +0 -11
- package/dist/ro-RO.module.js +0 -11
- package/dist/ro-RO.module.js.map +0 -1
- package/dist/ru-RU.main.js +0 -9
- package/dist/ru-RU.main.js.map +0 -1
- package/dist/ru-RU.mjs +0 -11
- package/dist/ru-RU.module.js +0 -11
- package/dist/ru-RU.module.js.map +0 -1
- package/dist/search_vars_css.main.js +0 -53
- package/dist/search_vars_css.main.js.map +0 -1
- package/dist/search_vars_css.mjs +0 -55
- package/dist/search_vars_css.module.js +0 -55
- package/dist/search_vars_css.module.js.map +0 -1
- package/dist/searchautocomplete_css.main.js +0 -38
- package/dist/searchautocomplete_css.main.js.map +0 -1
- package/dist/searchautocomplete_css.mjs +0 -40
- package/dist/searchautocomplete_css.module.js +0 -40
- package/dist/searchautocomplete_css.module.js.map +0 -1
- package/dist/sk-SK.main.js +0 -9
- package/dist/sk-SK.main.js.map +0 -1
- package/dist/sk-SK.mjs +0 -11
- package/dist/sk-SK.module.js +0 -11
- package/dist/sk-SK.module.js.map +0 -1
- package/dist/sl-SI.main.js +0 -9
- package/dist/sl-SI.main.js.map +0 -1
- package/dist/sl-SI.mjs +0 -11
- package/dist/sl-SI.module.js +0 -11
- package/dist/sl-SI.module.js.map +0 -1
- package/dist/sr-SP.main.js +0 -9
- package/dist/sr-SP.main.js.map +0 -1
- package/dist/sr-SP.mjs +0 -11
- package/dist/sr-SP.module.js +0 -11
- package/dist/sr-SP.module.js.map +0 -1
- package/dist/sv-SE.main.js +0 -9
- package/dist/sv-SE.main.js.map +0 -1
- package/dist/sv-SE.mjs +0 -11
- package/dist/sv-SE.module.js +0 -11
- package/dist/sv-SE.module.js.map +0 -1
- package/dist/textfield_vars_css.main.js +0 -74
- package/dist/textfield_vars_css.main.js.map +0 -1
- package/dist/textfield_vars_css.mjs +0 -76
- package/dist/textfield_vars_css.module.js +0 -76
- package/dist/textfield_vars_css.module.js.map +0 -1
- package/dist/tr-TR.main.js +0 -9
- package/dist/tr-TR.main.js.map +0 -1
- package/dist/tr-TR.mjs +0 -11
- package/dist/tr-TR.module.js +0 -11
- package/dist/tr-TR.module.js.map +0 -1
- package/dist/types.d.ts +0 -13
- package/dist/types.d.ts.map +0 -1
- package/dist/uk-UA.main.js +0 -9
- package/dist/uk-UA.main.js.map +0 -1
- package/dist/uk-UA.mjs +0 -11
- package/dist/uk-UA.module.js +0 -11
- package/dist/uk-UA.module.js.map +0 -1
- package/dist/zh-CN.main.js +0 -9
- package/dist/zh-CN.main.js.map +0 -1
- package/dist/zh-CN.mjs +0 -11
- package/dist/zh-CN.module.js +0 -11
- package/dist/zh-CN.module.js.map +0 -1
- package/dist/zh-TW.main.js +0 -9
- package/dist/zh-TW.main.js.map +0 -1
- package/dist/zh-TW.mjs +0 -11
- package/dist/zh-TW.module.js +0 -11
- package/dist/zh-TW.module.js.map +0 -1
- package/src/MobileSearchAutocomplete.tsx +0 -632
- package/src/SearchAutocomplete.tsx +0 -382
- 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
|
-
}
|