Skip to content

Commit 5ccf5b7

Browse files
authored
chore: Updating name of useAutocomplete textfieldProps to inputProps (#8762)
* chore: Updating name of useAutocomplete textfieldProps to something more generic * actually use new type whoops
1 parent e3037d6 commit 5ccf5b7

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

packages/@react-aria/autocomplete/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export {useAutocomplete} from './useAutocomplete';
1414

1515
export type {AriaSearchAutocompleteOptions, SearchAutocompleteAria} from './useSearchAutocomplete';
1616
export type {AriaSearchAutocompleteProps} from '@react-types/autocomplete';
17-
export type {AriaAutocompleteProps, AriaAutocompleteOptions, AutocompleteAria, CollectionOptions} from './useAutocomplete';
17+
export type {AriaAutocompleteProps, AriaAutocompleteOptions, AutocompleteAria, CollectionOptions, InputProps} from './useAutocomplete';

packages/@react-aria/autocomplete/src/useAutocomplete.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {AriaLabelingProps, BaseEvent, DOMProps, FocusableElement, Node, RefObject} from '@react-types/shared';
13+
import {AriaLabelingProps, BaseEvent, DOMProps, FocusableElement, FocusEvents, KeyboardEvents, Node, RefObject, ValueBase} from '@react-types/shared';
1414
import {AriaTextFieldProps} from '@react-aria/textfield';
1515
import {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';
1616
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useLabels, useObjectRef, useSlotId} from '@react-aria/utils';
@@ -28,6 +28,12 @@ export interface CollectionOptions extends DOMProps, AriaLabelingProps {
2828
disallowTypeAhead: boolean
2929
}
3030

31+
export interface InputProps<T = FocusableElement> extends DOMProps,
32+
FocusEvents<T>,
33+
KeyboardEvents,
34+
Pick<ValueBase<string>, 'onChange' | 'value'>,
35+
Pick<AriaTextFieldProps, 'enterKeyHint' | 'aria-controls' | 'aria-autocomplete' | 'aria-activedescendant' | 'spellCheck' | 'autoCorrect' | 'autoComplete'> {}
36+
3137
export interface AriaAutocompleteProps<T> extends AutocompleteProps {
3238
/**
3339
* An optional filter function used to determine if a option should be included in the autocomplete list.
@@ -57,8 +63,8 @@ export interface AriaAutocompleteOptions<T> extends Omit<AriaAutocompleteProps<T
5763
}
5864

5965
export interface AutocompleteAria<T> {
60-
/** Props for the autocomplete textfield/searchfield element. These should be passed to the textfield/searchfield aria hooks respectively. */
61-
textFieldProps: AriaTextFieldProps<FocusableElement>,
66+
/** Props for the autocomplete input element. These should be passed to the input's aria hooks (e.g. useTextField/useSearchField/etc) respectively. */
67+
inputProps: InputProps,
6268
/** Props for the collection, to be passed to collection's respective aria hook (e.g. useMenu). */
6369
collectionProps: CollectionOptions,
6470
/** Ref to attach to the wrapped collection. */
@@ -368,7 +374,7 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
368374

369375
// Only apply the autocomplete specific behaviors if the collection component wrapped by it is actually
370376
// being filtered/allows filtering by the Autocomplete.
371-
let textFieldProps = {
377+
let inputProps = {
372378
value: state.inputValue,
373379
onChange
374380
} as AriaTextFieldProps<FocusableElement>;
@@ -381,8 +387,8 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
381387
};
382388

383389
if (collectionId) {
384-
textFieldProps = {
385-
...textFieldProps,
390+
inputProps = {
391+
...inputProps,
386392
...(shouldUseVirtualFocus && virtualFocusProps),
387393
enterKeyHint: 'go',
388394
'aria-controls': collectionId,
@@ -397,7 +403,7 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
397403
}
398404

399405
return {
400-
textFieldProps,
406+
inputProps,
401407
collectionProps: mergeProps(collectionProps, {
402408
shouldUseVirtualFocus,
403409
disallowTypeAhead: true

packages/react-aria-components/src/Autocomplete.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function Autocomplete<T extends object>(props: AutocompleteProps<T>): JSX
3232
let inputRef = useRef<HTMLInputElement | null>(null);
3333
let collectionRef = useRef<HTMLElement>(null);
3434
let {
35-
textFieldProps,
35+
inputProps,
3636
collectionProps,
3737
collectionRef: mergedCollectionRef,
3838
filter: filterFn
@@ -49,7 +49,7 @@ export function Autocomplete<T extends object>(props: AutocompleteProps<T>): JSX
4949
values={[
5050
[AutocompleteStateContext, state],
5151
[FieldInputContext, {
52-
...textFieldProps,
52+
...inputProps,
5353
ref: inputRef
5454
}],
5555
[SelectableCollectionContext, {

0 commit comments

Comments
 (0)