@react-spectrum/combobox 3.16.7 → 3.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) 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/ComboBox.main.js +0 -305
  10. package/dist/ComboBox.main.js.map +0 -1
  11. package/dist/ComboBox.mjs +0 -300
  12. package/dist/ComboBox.module.js +0 -300
  13. package/dist/ComboBox.module.js.map +0 -1
  14. package/dist/MobileComboBox.main.js +0 -432
  15. package/dist/MobileComboBox.main.js.map +0 -1
  16. package/dist/MobileComboBox.mjs +0 -427
  17. package/dist/MobileComboBox.module.js +0 -427
  18. package/dist/MobileComboBox.module.js.map +0 -1
  19. package/dist/ar-AE.main.js +0 -10
  20. package/dist/ar-AE.main.js.map +0 -1
  21. package/dist/ar-AE.mjs +0 -12
  22. package/dist/ar-AE.module.js +0 -12
  23. package/dist/ar-AE.module.js.map +0 -1
  24. package/dist/bg-BG.main.js +0 -10
  25. package/dist/bg-BG.main.js.map +0 -1
  26. package/dist/bg-BG.mjs +0 -12
  27. package/dist/bg-BG.module.js +0 -12
  28. package/dist/bg-BG.module.js.map +0 -1
  29. package/dist/button_vars_css.main.js +0 -125
  30. package/dist/button_vars_css.main.js.map +0 -1
  31. package/dist/button_vars_css.mjs +0 -127
  32. package/dist/button_vars_css.module.js +0 -127
  33. package/dist/button_vars_css.module.js.map +0 -1
  34. package/dist/combobox.1c1869da.css +0 -50
  35. package/dist/combobox.1c1869da.css.map +0 -1
  36. package/dist/combobox.32e7c48f.css +0 -550
  37. package/dist/combobox.32e7c48f.css.map +0 -1
  38. package/dist/combobox.8958325b.css +0 -1669
  39. package/dist/combobox.8958325b.css.map +0 -1
  40. package/dist/combobox.a38acc5c.css +0 -649
  41. package/dist/combobox.a38acc5c.css.map +0 -1
  42. package/dist/combobox.cab3a9ff.css +0 -271
  43. package/dist/combobox.cab3a9ff.css.map +0 -1
  44. package/dist/combobox.cce0a74c.css +0 -223
  45. package/dist/combobox.cce0a74c.css.map +0 -1
  46. package/dist/combobox_css.main.js +0 -35
  47. package/dist/combobox_css.main.js.map +0 -1
  48. package/dist/combobox_css.mjs +0 -37
  49. package/dist/combobox_css.module.js +0 -37
  50. package/dist/combobox_css.module.js.map +0 -1
  51. package/dist/cs-CZ.main.js +0 -10
  52. package/dist/cs-CZ.main.js.map +0 -1
  53. package/dist/cs-CZ.mjs +0 -12
  54. package/dist/cs-CZ.module.js +0 -12
  55. package/dist/cs-CZ.module.js.map +0 -1
  56. package/dist/da-DK.main.js +0 -10
  57. package/dist/da-DK.main.js.map +0 -1
  58. package/dist/da-DK.mjs +0 -12
  59. package/dist/da-DK.module.js +0 -12
  60. package/dist/da-DK.module.js.map +0 -1
  61. package/dist/de-DE.main.js +0 -10
  62. package/dist/de-DE.main.js.map +0 -1
  63. package/dist/de-DE.mjs +0 -12
  64. package/dist/de-DE.module.js +0 -12
  65. package/dist/de-DE.module.js.map +0 -1
  66. package/dist/el-GR.main.js +0 -10
  67. package/dist/el-GR.main.js.map +0 -1
  68. package/dist/el-GR.mjs +0 -12
  69. package/dist/el-GR.module.js +0 -12
  70. package/dist/el-GR.module.js.map +0 -1
  71. package/dist/en-US.main.js +0 -10
  72. package/dist/en-US.main.js.map +0 -1
  73. package/dist/en-US.mjs +0 -12
  74. package/dist/en-US.module.js +0 -12
  75. package/dist/en-US.module.js.map +0 -1
  76. package/dist/es-ES.main.js +0 -10
  77. package/dist/es-ES.main.js.map +0 -1
  78. package/dist/es-ES.mjs +0 -12
  79. package/dist/es-ES.module.js +0 -12
  80. package/dist/es-ES.module.js.map +0 -1
  81. package/dist/et-EE.main.js +0 -10
  82. package/dist/et-EE.main.js.map +0 -1
  83. package/dist/et-EE.mjs +0 -12
  84. package/dist/et-EE.module.js +0 -12
  85. package/dist/et-EE.module.js.map +0 -1
  86. package/dist/fi-FI.main.js +0 -10
  87. package/dist/fi-FI.main.js.map +0 -1
  88. package/dist/fi-FI.mjs +0 -12
  89. package/dist/fi-FI.module.js +0 -12
  90. package/dist/fi-FI.module.js.map +0 -1
  91. package/dist/fieldlabel_vars_css.main.js +0 -95
  92. package/dist/fieldlabel_vars_css.main.js.map +0 -1
  93. package/dist/fieldlabel_vars_css.mjs +0 -97
  94. package/dist/fieldlabel_vars_css.module.js +0 -97
  95. package/dist/fieldlabel_vars_css.module.js.map +0 -1
  96. package/dist/fr-FR.main.js +0 -10
  97. package/dist/fr-FR.main.js.map +0 -1
  98. package/dist/fr-FR.mjs +0 -12
  99. package/dist/fr-FR.module.js +0 -12
  100. package/dist/fr-FR.module.js.map +0 -1
  101. package/dist/he-IL.main.js +0 -10
  102. package/dist/he-IL.main.js.map +0 -1
  103. package/dist/he-IL.mjs +0 -12
  104. package/dist/he-IL.module.js +0 -12
  105. package/dist/he-IL.module.js.map +0 -1
  106. package/dist/hr-HR.main.js +0 -10
  107. package/dist/hr-HR.main.js.map +0 -1
  108. package/dist/hr-HR.mjs +0 -12
  109. package/dist/hr-HR.module.js +0 -12
  110. package/dist/hr-HR.module.js.map +0 -1
  111. package/dist/hu-HU.main.js +0 -10
  112. package/dist/hu-HU.main.js.map +0 -1
  113. package/dist/hu-HU.mjs +0 -12
  114. package/dist/hu-HU.module.js +0 -12
  115. package/dist/hu-HU.module.js.map +0 -1
  116. package/dist/inputgroup_vars_css.main.js +0 -86
  117. package/dist/inputgroup_vars_css.main.js.map +0 -1
  118. package/dist/inputgroup_vars_css.mjs +0 -88
  119. package/dist/inputgroup_vars_css.module.js +0 -88
  120. package/dist/inputgroup_vars_css.module.js.map +0 -1
  121. package/dist/intlStrings.main.js +0 -108
  122. package/dist/intlStrings.main.js.map +0 -1
  123. package/dist/intlStrings.mjs +0 -110
  124. package/dist/intlStrings.module.js +0 -110
  125. package/dist/intlStrings.module.js.map +0 -1
  126. package/dist/it-IT.main.js +0 -10
  127. package/dist/it-IT.main.js.map +0 -1
  128. package/dist/it-IT.mjs +0 -12
  129. package/dist/it-IT.module.js +0 -12
  130. package/dist/it-IT.module.js.map +0 -1
  131. package/dist/ja-JP.main.js +0 -10
  132. package/dist/ja-JP.main.js.map +0 -1
  133. package/dist/ja-JP.mjs +0 -12
  134. package/dist/ja-JP.module.js +0 -12
  135. package/dist/ja-JP.module.js.map +0 -1
  136. package/dist/ko-KR.main.js +0 -10
  137. package/dist/ko-KR.main.js.map +0 -1
  138. package/dist/ko-KR.mjs +0 -12
  139. package/dist/ko-KR.module.js +0 -12
  140. package/dist/ko-KR.module.js.map +0 -1
  141. package/dist/lt-LT.main.js +0 -10
  142. package/dist/lt-LT.main.js.map +0 -1
  143. package/dist/lt-LT.mjs +0 -12
  144. package/dist/lt-LT.module.js +0 -12
  145. package/dist/lt-LT.module.js.map +0 -1
  146. package/dist/lv-LV.main.js +0 -10
  147. package/dist/lv-LV.main.js.map +0 -1
  148. package/dist/lv-LV.mjs +0 -12
  149. package/dist/lv-LV.module.js +0 -12
  150. package/dist/lv-LV.module.js.map +0 -1
  151. package/dist/nb-NO.main.js +0 -10
  152. package/dist/nb-NO.main.js.map +0 -1
  153. package/dist/nb-NO.mjs +0 -12
  154. package/dist/nb-NO.module.js +0 -12
  155. package/dist/nb-NO.module.js.map +0 -1
  156. package/dist/nl-NL.main.js +0 -10
  157. package/dist/nl-NL.main.js.map +0 -1
  158. package/dist/nl-NL.mjs +0 -12
  159. package/dist/nl-NL.module.js +0 -12
  160. package/dist/nl-NL.module.js.map +0 -1
  161. package/dist/pl-PL.main.js +0 -10
  162. package/dist/pl-PL.main.js.map +0 -1
  163. package/dist/pl-PL.mjs +0 -12
  164. package/dist/pl-PL.module.js +0 -12
  165. package/dist/pl-PL.module.js.map +0 -1
  166. package/dist/pt-BR.main.js +0 -10
  167. package/dist/pt-BR.main.js.map +0 -1
  168. package/dist/pt-BR.mjs +0 -12
  169. package/dist/pt-BR.module.js +0 -12
  170. package/dist/pt-BR.module.js.map +0 -1
  171. package/dist/pt-PT.main.js +0 -10
  172. package/dist/pt-PT.main.js.map +0 -1
  173. package/dist/pt-PT.mjs +0 -12
  174. package/dist/pt-PT.module.js +0 -12
  175. package/dist/pt-PT.module.js.map +0 -1
  176. package/dist/ro-RO.main.js +0 -10
  177. package/dist/ro-RO.main.js.map +0 -1
  178. package/dist/ro-RO.mjs +0 -12
  179. package/dist/ro-RO.module.js +0 -12
  180. package/dist/ro-RO.module.js.map +0 -1
  181. package/dist/ru-RU.main.js +0 -10
  182. package/dist/ru-RU.main.js.map +0 -1
  183. package/dist/ru-RU.mjs +0 -12
  184. package/dist/ru-RU.module.js +0 -12
  185. package/dist/ru-RU.module.js.map +0 -1
  186. package/dist/search_vars_css.main.js +0 -53
  187. package/dist/search_vars_css.main.js.map +0 -1
  188. package/dist/search_vars_css.mjs +0 -55
  189. package/dist/search_vars_css.module.js +0 -55
  190. package/dist/search_vars_css.module.js.map +0 -1
  191. package/dist/sk-SK.main.js +0 -10
  192. package/dist/sk-SK.main.js.map +0 -1
  193. package/dist/sk-SK.mjs +0 -12
  194. package/dist/sk-SK.module.js +0 -12
  195. package/dist/sk-SK.module.js.map +0 -1
  196. package/dist/sl-SI.main.js +0 -10
  197. package/dist/sl-SI.main.js.map +0 -1
  198. package/dist/sl-SI.mjs +0 -12
  199. package/dist/sl-SI.module.js +0 -12
  200. package/dist/sl-SI.module.js.map +0 -1
  201. package/dist/sr-SP.main.js +0 -10
  202. package/dist/sr-SP.main.js.map +0 -1
  203. package/dist/sr-SP.mjs +0 -12
  204. package/dist/sr-SP.module.js +0 -12
  205. package/dist/sr-SP.module.js.map +0 -1
  206. package/dist/sv-SE.main.js +0 -10
  207. package/dist/sv-SE.main.js.map +0 -1
  208. package/dist/sv-SE.mjs +0 -12
  209. package/dist/sv-SE.module.js +0 -12
  210. package/dist/sv-SE.module.js.map +0 -1
  211. package/dist/textfield_vars_css.main.js +0 -74
  212. package/dist/textfield_vars_css.main.js.map +0 -1
  213. package/dist/textfield_vars_css.mjs +0 -76
  214. package/dist/textfield_vars_css.module.js +0 -76
  215. package/dist/textfield_vars_css.module.js.map +0 -1
  216. package/dist/tr-TR.main.js +0 -10
  217. package/dist/tr-TR.main.js.map +0 -1
  218. package/dist/tr-TR.mjs +0 -12
  219. package/dist/tr-TR.module.js +0 -12
  220. package/dist/tr-TR.module.js.map +0 -1
  221. package/dist/types.d.ts +0 -13
  222. package/dist/types.d.ts.map +0 -1
  223. package/dist/uk-UA.main.js +0 -10
  224. package/dist/uk-UA.main.js.map +0 -1
  225. package/dist/uk-UA.mjs +0 -12
  226. package/dist/uk-UA.module.js +0 -12
  227. package/dist/uk-UA.module.js.map +0 -1
  228. package/dist/zh-CN.main.js +0 -10
  229. package/dist/zh-CN.main.js.map +0 -1
  230. package/dist/zh-CN.mjs +0 -12
  231. package/dist/zh-CN.module.js +0 -12
  232. package/dist/zh-CN.module.js.map +0 -1
  233. package/dist/zh-TW.main.js +0 -10
  234. package/dist/zh-TW.main.js.map +0 -1
  235. package/dist/zh-TW.mjs +0 -12
  236. package/dist/zh-TW.module.js +0 -12
  237. package/dist/zh-TW.module.js.map +0 -1
  238. package/src/ComboBox.tsx +0 -376
  239. package/src/MobileComboBox.tsx +0 -571
  240. package/src/combobox.css +0 -65
@@ -1,571 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import AlertMedium from '@spectrum-icons/ui/AlertMedium';
14
- import {AriaButtonProps} from '@react-types/button';
15
- import buttonStyles from '@adobe/spectrum-css-temp/components/button/vars.css';
16
- import CheckmarkMedium from '@spectrum-icons/ui/CheckmarkMedium';
17
- import ChevronDownMedium from '@spectrum-icons/ui/ChevronDownMedium';
18
- import {classNames, unwrapDOMRef, useFocusableRef} from '@react-spectrum/utils';
19
- import {ClearButton} from '@react-spectrum/button';
20
- import {ComboBoxState, useComboBoxState} from '@react-stately/combobox';
21
- import comboboxStyles from './combobox.css';
22
- import {DismissButton, useOverlayTrigger} from '@react-aria/overlays';
23
- import {Field} from '@react-spectrum/label';
24
- import {FocusableRef, FocusableRefValue, ValidationState} from '@react-types/shared';
25
- import {FocusRing, FocusScope} from '@react-aria/focus';
26
- import {focusSafely, setInteractionModality, useHover} from '@react-aria/interactions';
27
- import {getActiveElement, mergeProps, useFormReset, useId, useObjectRef} from '@react-aria/utils';
28
- // @ts-ignore
29
- import intlMessages from '../intl/*.json';
30
- import labelStyles from '@adobe/spectrum-css-temp/components/fieldlabel/vars.css';
31
- import {ListBoxBase, useListBoxLayout} from '@react-spectrum/listbox';
32
- import {ProgressCircle} from '@react-spectrum/progress';
33
- import React, {ForwardedRef, HTMLAttributes, InputHTMLAttributes, ReactElement, ReactNode, useCallback, useEffect, useRef, useState} from 'react';
34
- import searchStyles from '@adobe/spectrum-css-temp/components/search/vars.css';
35
- import {SpectrumComboBoxProps} from '@react-types/combobox';
36
- import styles from '@adobe/spectrum-css-temp/components/inputgroup/vars.css';
37
- import {TextFieldBase} from '@react-spectrum/textfield';
38
- import textfieldStyles from '@adobe/spectrum-css-temp/components/textfield/vars.css';
39
- import {Tray} from '@react-spectrum/overlays';
40
- import {useButton} from '@react-aria/button';
41
- import {useComboBox} from '@react-aria/combobox';
42
- import {useDialog} from '@react-aria/dialog';
43
- import {useField} from '@react-aria/label';
44
- import {useFilter, useLocalizedStringFormatter} from '@react-aria/i18n';
45
- import {useFormValidation} from '@react-aria/form';
46
- import {useProviderProps} from '@react-spectrum/provider';
47
-
48
- export const MobileComboBox = React.forwardRef(function MobileComboBox(props: SpectrumComboBoxProps<any>, ref: FocusableRef<HTMLElement>) {
49
- props = useProviderProps(props);
50
-
51
- let {
52
- isQuiet,
53
- isDisabled,
54
- isReadOnly,
55
- isRequired,
56
- validationBehavior,
57
- name,
58
- formValue = 'text',
59
- allowsCustomValue
60
- } = props;
61
- if (allowsCustomValue) {
62
- formValue = 'text';
63
- }
64
-
65
- let {contains} = useFilter({sensitivity: 'base'});
66
- let state = useComboBoxState({
67
- ...props,
68
- defaultFilter: contains,
69
- allowsEmptyCollection: true,
70
- // Needs to be false here otherwise we double up on commitSelection/commitCustomValue calls when
71
- // user taps on underlay (i.e. initial tap will call setFocused(false) -> commitSelection/commitCustomValue via onBlur,
72
- // then the closing of the tray will call setFocused(false) again due to cleanup effect)
73
- shouldCloseOnBlur: false
74
- });
75
-
76
- let buttonRef = useRef<HTMLDivElement>(null);
77
- let domRef = useFocusableRef(ref, buttonRef);
78
- let {triggerProps, overlayProps} = useOverlayTrigger({type: 'listbox'}, state, buttonRef);
79
-
80
- let inputRef = useRef<HTMLInputElement>(null);
81
- useFormValidation({
82
- ...props,
83
- focus: () => buttonRef.current?.focus()
84
- }, state, inputRef);
85
- let {isInvalid, validationErrors, validationDetails} = state.displayValidation;
86
- let validationState = props.validationState || (isInvalid ? 'invalid' : undefined);
87
- let errorMessage = props.errorMessage ?? validationErrors.join(' ');
88
-
89
- let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
90
- ...props,
91
- labelElementType: 'span',
92
- isInvalid,
93
- errorMessage
94
- });
95
-
96
- // Focus the button and show focus ring when clicking on the label
97
- labelProps.onClick = () => {
98
- if (!props.isDisabled) {
99
- buttonRef.current?.focus();
100
- setInteractionModality('keyboard');
101
- }
102
- };
103
-
104
- let inputProps: InputHTMLAttributes<HTMLInputElement> = {
105
- type: 'hidden',
106
- name,
107
- value: formValue === 'text' ? state.inputValue : String(state.selectedKey)
108
- };
109
-
110
- if (validationBehavior === 'native') {
111
- // Use a hidden <input type="text"> rather than <input type="hidden">
112
- // so that an empty value blocks HTML form submission when the field is required.
113
- inputProps.type = 'text';
114
- inputProps.hidden = true;
115
- inputProps.required = isRequired;
116
- // Ignore react warning.
117
- inputProps.onChange = () => {};
118
- }
119
-
120
- useFormReset<any>(
121
- inputRef,
122
- formValue === 'text' ? state.defaultInputValue : state.defaultSelectedKey,
123
- formValue === 'text' ? state.setInputValue : state.setSelectedKey
124
- );
125
-
126
- return (
127
- <>
128
- <Field
129
- {...props}
130
- labelProps={labelProps}
131
- descriptionProps={descriptionProps}
132
- errorMessageProps={errorMessageProps}
133
- validationState={validationState}
134
- isInvalid={isInvalid}
135
- validationErrors={validationErrors}
136
- validationDetails={validationDetails}
137
- elementType="span"
138
- ref={domRef}
139
- includeNecessityIndicatorInAccessibilityName>
140
- <ComboBoxButton
141
- {...mergeProps(triggerProps, fieldProps, {autoFocus: props.autoFocus})}
142
- ref={buttonRef}
143
- isQuiet={isQuiet}
144
- isDisabled={isDisabled}
145
- isPlaceholder={!state.inputValue}
146
- validationState={validationState}
147
- onPress={() => !isReadOnly && state.open(null, 'manual')}>
148
- {state.inputValue || props.placeholder || ''}
149
- </ComboBoxButton>
150
- </Field>
151
- <input {...inputProps} ref={inputRef} />
152
- <Tray state={state} isFixedHeight {...overlayProps}>
153
- <ComboBoxTray
154
- {...props}
155
- onClose={state.close}
156
- overlayProps={overlayProps}
157
- state={state} />
158
- </Tray>
159
- </>
160
- );
161
- });
162
-
163
- interface ComboBoxButtonProps extends AriaButtonProps {
164
- isQuiet?: boolean,
165
- isDisabled?: boolean,
166
- isPlaceholder?: boolean,
167
- validationState?: ValidationState,
168
- children?: ReactNode,
169
- style?: React.CSSProperties,
170
- className?: string
171
- }
172
-
173
- export const ComboBoxButton = React.forwardRef(function ComboBoxButton(props: ComboBoxButtonProps, ref: ForwardedRef<HTMLDivElement>) {
174
- let {
175
- isQuiet,
176
- isDisabled,
177
- isPlaceholder,
178
- validationState,
179
- children,
180
- style,
181
- className
182
- } = props;
183
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/combobox');
184
- let valueId = useId();
185
- let invalidId = useId();
186
- let validId = useId();
187
- let validationIcon = validationState === 'invalid'
188
- ? <AlertMedium id={invalidId} aria-label={stringFormatter.format('invalid')} />
189
- : <CheckmarkMedium id={validId} aria-label={stringFormatter.format('valid')} />;
190
-
191
- let validation = React.cloneElement(validationIcon, {
192
- UNSAFE_className: classNames(
193
- textfieldStyles,
194
- 'spectrum-Textfield-validationIcon',
195
- classNames(
196
- styles,
197
- 'spectrum-InputGroup-input-validationIcon'
198
- )
199
- )
200
- });
201
-
202
- let objRef = useObjectRef(ref);
203
- let {hoverProps, isHovered} = useHover({});
204
- let {buttonProps, isPressed} = useButton({
205
- ...props,
206
- 'aria-labelledby': [
207
- props['aria-labelledby'],
208
- props['aria-label'] && !props['aria-labelledby'] ? props.id : null,
209
- valueId,
210
- validationState === 'invalid' ? invalidId : null,
211
- validationState === 'valid' ? validId : null
212
- ].filter(Boolean).join(' '),
213
- elementType: 'div'
214
- }, objRef);
215
-
216
- return (
217
- (<FocusRing
218
- focusClass={classNames(styles, 'is-focused')}
219
- focusRingClass={classNames(styles, 'focus-ring')}>
220
- <div
221
- {...mergeProps(hoverProps, buttonProps)}
222
- aria-haspopup="dialog"
223
- ref={objRef}
224
- style={{...style, outline: 'none'}}
225
- className={
226
- classNames(
227
- styles,
228
- 'spectrum-InputGroup',
229
- {
230
- 'spectrum-InputGroup--quiet': isQuiet,
231
- 'is-disabled': isDisabled,
232
- 'spectrum-InputGroup--invalid': validationState === 'invalid' && !isDisabled,
233
- 'is-hovered': isHovered
234
- },
235
- classNames(
236
- comboboxStyles,
237
- 'mobile-combobox'
238
- ),
239
- className
240
- )
241
- }>
242
- <div
243
- className={
244
- classNames(
245
- textfieldStyles,
246
- 'spectrum-Textfield',
247
- {
248
- 'spectrum-Textfield--invalid': validationState === 'invalid' && !isDisabled,
249
- 'spectrum-Textfield--valid': validationState === 'valid' && !isDisabled,
250
- 'spectrum-Textfield--quiet': isQuiet
251
- },
252
- classNames(
253
- styles,
254
- 'spectrum-InputGroup-field'
255
- )
256
- )
257
- }>
258
- <div
259
- className={
260
- classNames(
261
- textfieldStyles,
262
- 'spectrum-Textfield-input',
263
- {
264
- 'is-hovered': isHovered,
265
- 'is-placeholder': isPlaceholder,
266
- 'is-disabled': isDisabled
267
- },
268
- classNames(
269
- styles,
270
- 'spectrum-InputGroup-input',
271
- classNames(labelStyles, 'spectrum-Field-field')
272
- ),
273
- classNames(
274
- comboboxStyles,
275
- 'mobile-input'
276
- )
277
- )
278
- }>
279
- <span
280
- id={valueId}
281
- className={
282
- classNames(
283
- comboboxStyles,
284
- 'mobile-value'
285
- )
286
- }>
287
- {children}
288
- </span>
289
- </div>
290
- {validationState && !isDisabled ? validation : null}
291
- </div>
292
- <div
293
- className={
294
- classNames(
295
- buttonStyles,
296
- 'spectrum-FieldButton',
297
- {
298
- 'spectrum-FieldButton--quiet': isQuiet,
299
- 'is-active': isPressed,
300
- 'is-disabled': isDisabled,
301
- 'spectrum-FieldButton--invalid': validationState === 'invalid' && !isDisabled,
302
- 'is-hovered': isHovered
303
- },
304
- classNames(
305
- styles,
306
- 'spectrum-FieldButton'
307
- )
308
- )
309
- }>
310
- <ChevronDownMedium UNSAFE_className={classNames(styles, 'spectrum-Dropdown-chevron')} />
311
- </div>
312
- </div>
313
- </FocusRing>)
314
- );
315
- });
316
-
317
- interface ComboBoxTrayProps extends SpectrumComboBoxProps<any> {
318
- state: ComboBoxState<any>,
319
- overlayProps: HTMLAttributes<HTMLElement>,
320
- loadingIndicator?: ReactElement,
321
- onClose: () => void
322
- }
323
-
324
- function ComboBoxTray(props: ComboBoxTrayProps) {
325
- let {
326
- // completionMode = 'suggest',
327
- state,
328
- isDisabled,
329
- validationState,
330
- label,
331
- overlayProps,
332
- loadingState,
333
- onLoadMore,
334
- onClose
335
- } = props;
336
-
337
- let timeout = useRef<ReturnType<typeof setTimeout> | null>(null);
338
- let [showLoading, setShowLoading] = useState(false);
339
- let inputRef = useRef<HTMLInputElement>(null);
340
- let buttonRef = useRef<FocusableRefValue<HTMLElement>>(null);
341
- let popoverRef = useRef<HTMLDivElement>(null);
342
- let listBoxRef = useRef<HTMLDivElement>(null);
343
- let isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
344
- let layout = useListBoxLayout();
345
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/combobox');
346
-
347
- let {inputProps, listBoxProps, labelProps} = useComboBox(
348
- {
349
- ...props,
350
- // completionMode,
351
- layoutDelegate: layout,
352
- buttonRef: unwrapDOMRef(buttonRef),
353
- popoverRef: popoverRef,
354
- listBoxRef,
355
- inputRef,
356
- // Handled outside the tray.
357
- name: undefined
358
- },
359
- state
360
- );
361
-
362
- React.useEffect(() => {
363
- if (inputRef.current) {
364
- focusSafely(inputRef.current);
365
- }
366
- }, []);
367
-
368
- React.useEffect(() => {
369
- // When the tray closes, set state.isFocused (i.e. the tray input's focus tracker) to false.
370
- // This is to prevent state.isFocused from being set to true when the tray closes via tapping on the underlay
371
- // (FocusScope attempts to restore focus to the tray input when tapping outside the tray due to "contain")
372
- // Have to do this manually since React doesn't call onBlur when a component is unmounted: https://github.com/facebook/react/issues/12363
373
- if (!state.isOpen && state.isFocused) {
374
- state.setFocused(false);
375
- }
376
- });
377
-
378
- let {dialogProps} = useDialog({
379
- 'aria-labelledby': useId(labelProps.id)
380
- }, popoverRef);
381
-
382
- // Override the role of the input to "searchbox" instead of "combobox".
383
- // Since the listbox is always visible, the combobox role doesn't really give us anything.
384
- // VoiceOver on iOS reads "double tap to collapse" when focused on the input rather than
385
- // "double tap to edit text", as with a textbox or searchbox. We'd like double tapping to
386
- // open the virtual keyboard rather than closing the tray.
387
- // Unlike "combobox", "aria-expanded" is not a valid attribute on "searchbox".
388
- inputProps.role = 'searchbox';
389
- inputProps['aria-haspopup'] = 'listbox';
390
- delete inputProps['aria-expanded'];
391
- delete inputProps.onTouchEnd;
392
-
393
- let clearButton = (
394
- <ClearButton
395
- preventFocus
396
- aria-label={stringFormatter.format('clear')}
397
- excludeFromTabOrder
398
- onPress={() => {
399
- state.setInputValue('');
400
- inputRef.current?.focus();
401
- }}
402
- UNSAFE_className={
403
- classNames(
404
- searchStyles,
405
- 'spectrum-ClearButton'
406
- )
407
- }
408
- isDisabled={isDisabled} />
409
- );
410
-
411
- let loadingCircle = (
412
- <ProgressCircle
413
- aria-label={stringFormatter.format('loading')}
414
- size="S"
415
- isIndeterminate
416
- UNSAFE_className={classNames(
417
- searchStyles,
418
- 'spectrum-Search-circleLoader',
419
- classNames(
420
- textfieldStyles,
421
- 'spectrum-Textfield-circleLoader'
422
- )
423
- )} />
424
- );
425
-
426
- // Close the software keyboard on scroll to give the user a bigger area to scroll.
427
- // But only do this if scrolling with touch, otherwise it can cause issues with touch
428
- // screen readers.
429
- let isTouchDown = useRef(false);
430
- let onTouchStart = () => {
431
- isTouchDown.current = true;
432
- };
433
-
434
- let onTouchEnd = () => {
435
- isTouchDown.current = false;
436
- };
437
-
438
- let onScroll = useCallback(() => {
439
- if (!inputRef.current || getActiveElement() !== inputRef.current || !isTouchDown.current) {
440
- return;
441
- }
442
-
443
- popoverRef.current?.focus();
444
- }, [inputRef, popoverRef, isTouchDown]);
445
-
446
- let inputValue = inputProps.value;
447
- let lastInputValue = useRef(inputValue);
448
- useEffect(() => {
449
- if (loadingState === 'filtering' && !showLoading) {
450
- if (timeout.current === null) {
451
- timeout.current = setTimeout(() => {
452
- setShowLoading(true);
453
- }, 500);
454
- }
455
-
456
- // If user is typing, clear the timer and restart since it is a new request
457
- if (inputValue !== lastInputValue.current) {
458
- clearTimeout(timeout.current);
459
- timeout.current = setTimeout(() => {
460
- setShowLoading(true);
461
- }, 500);
462
- }
463
- } else if (loadingState !== 'filtering') {
464
- // If loading is no longer happening, clear any timers and hide the loading circle
465
- setShowLoading(false);
466
- if (timeout.current) {
467
- clearTimeout(timeout.current);
468
- }
469
- timeout.current = null;
470
- }
471
-
472
- lastInputValue.current = inputValue;
473
- }, [loadingState, inputValue, showLoading]);
474
-
475
- let onKeyDown = (e) => {
476
- // Close virtual keyboard if user hits Enter w/o any focused options
477
- if (e.key === 'Enter' && state.selectionManager.focusedKey == null) {
478
- popoverRef.current?.focus();
479
- } else {
480
- inputProps.onKeyDown?.(e);
481
- }
482
- };
483
-
484
- return (
485
- <FocusScope restoreFocus contain>
486
- <div
487
- {...mergeProps(overlayProps, dialogProps)}
488
- ref={popoverRef}
489
- className={
490
- classNames(
491
- comboboxStyles,
492
- 'tray-dialog'
493
- )
494
- }>
495
- <DismissButton onDismiss={onClose} />
496
- <TextFieldBase
497
- label={label}
498
- labelProps={labelProps}
499
- inputProps={{...inputProps, onKeyDown}}
500
- inputRef={inputRef}
501
- isDisabled={isDisabled}
502
- isLoading={showLoading && loadingState === 'filtering'}
503
- loadingIndicator={loadingState != null ? loadingCircle : undefined}
504
- validationState={validationState}
505
- labelAlign="start"
506
- labelPosition="top"
507
- wrapperChildren={(state.inputValue !== '' || loadingState === 'filtering' || validationState != null) && !props.isReadOnly ? clearButton : undefined}
508
- UNSAFE_className={
509
- classNames(
510
- searchStyles,
511
- 'spectrum-Search',
512
- 'spectrum-Textfield',
513
- 'spectrum-Search--loadable',
514
- {
515
- 'spectrum-Search--invalid': validationState === 'invalid' && !isDisabled,
516
- 'spectrum-Search--valid': validationState === 'valid' && !isDisabled
517
- },
518
- classNames(
519
- comboboxStyles,
520
- 'tray-textfield',
521
- {
522
- 'has-label': !!props.label
523
- }
524
- )
525
- )
526
- }
527
- inputClassName={
528
- classNames(
529
- comboboxStyles,
530
- 'tray-textfield-input',
531
- classNames(
532
- searchStyles,
533
- 'spectrum-Search-input'
534
- )
535
- )
536
- }
537
- validationIconClassName={
538
- classNames(
539
- searchStyles,
540
- 'spectrum-Search-validationIcon'
541
- )
542
- } />
543
- <ListBoxBase
544
- {...listBoxProps}
545
- domProps={{onTouchStart, onTouchEnd}}
546
- disallowEmptySelection
547
- shouldSelectOnPressUp
548
- focusOnPointerEnter
549
- layout={layout}
550
- state={state}
551
- shouldUseVirtualFocus
552
- renderEmptyState={() => loadingState !== 'loading' && (
553
- <span className={classNames(comboboxStyles, 'no-results')}>
554
- {stringFormatter.format('noResults')}
555
- </span>
556
- )}
557
- UNSAFE_className={
558
- classNames(
559
- comboboxStyles,
560
- 'tray-listbox'
561
- )
562
- }
563
- ref={listBoxRef}
564
- onScroll={onScroll}
565
- onLoadMore={onLoadMore}
566
- isLoading={isLoading} />
567
- <DismissButton onDismiss={onClose} />
568
- </div>
569
- </FocusScope>
570
- );
571
- }
package/src/combobox.css DELETED
@@ -1,65 +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
- .mobile-combobox {
26
- outline: none;
27
- }
28
-
29
- .mobile-input {
30
- display: flex;
31
- align-items: center;
32
- }
33
-
34
- .mobile-value {
35
- white-space: nowrap;
36
- overflow: hidden;
37
- text-overflow: ellipsis;
38
- }
39
-
40
- .tray-dialog {
41
- display: flex;
42
- flex-direction: column;
43
- height: 100%;
44
- outline: none;
45
- }
46
-
47
- .tray-textfield {
48
- margin: var(--spectrum-global-dimension-size-150);
49
- margin-bottom: var(--spectrum-global-dimension-size-50);
50
- flex-shrink: 0;
51
- width: initial !important;
52
-
53
- &.has-label {
54
- margin-top: var(--spectrum-global-dimension-size-50);
55
- }
56
-
57
- .tray-textfield-input {
58
- padding-inline-start: var(--spectrum-textfield-padding-x);
59
- }
60
- }
61
-
62
- .tray-listbox {
63
- width: 100%;
64
- flex: 1;
65
- }