Skip to content

Commit

Permalink
get rid of inputRef and fix color field types
Browse files Browse the repository at this point in the history
  • Loading branch information
LFDanLu committed Jan 14, 2025
1 parent d4ea169 commit 8f42edb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
13 changes: 6 additions & 7 deletions packages/@react-aria/autocomplete/src/useAutocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export interface AriaAutocompleteProps extends AutocompleteProps {

export interface AriaAutocompleteOptions extends Omit<AriaAutocompleteProps, 'children'> {
/** The ref for the wrapped collection element. */
collectionRef: RefObject<HTMLElement | null>,
/** The ref for the wrapped input element. */
inputRef: RefObject<HTMLInputElement | null>
collectionRef: RefObject<HTMLElement | null>
}

export interface AutocompleteAria {
Expand All @@ -60,8 +58,7 @@ export interface AutocompleteAria {
export function UNSTABLE_useAutocomplete(props: AriaAutocompleteOptions, state: AutocompleteState): AutocompleteAria {
let {
collectionRef,
filter,
inputRef
filter
} = props;

let collectionId = useId();
Expand Down Expand Up @@ -150,8 +147,10 @@ export function UNSTABLE_useAutocomplete(props: AriaAutocompleteOptions, state:
state.setInputValue(value);
};

let keyDownTarget = useRef<Element | null>(null);
// For textfield specific keydown operations
let onKeyDown = (e: BaseEvent<ReactKeyboardEvent<any>>) => {
keyDownTarget.current = e.target as Element;
if (e.nativeEvent.isComposing) {
return;
}
Expand Down Expand Up @@ -228,7 +227,7 @@ export function UNSTABLE_useAutocomplete(props: AriaAutocompleteOptions, state:
// Dispatch simulated key up events for things like triggering links in listbox
// Make sure to stop the propagation of the input keyup event so that the simulated keyup/down pair
// is detected by usePress instead of the original keyup originating from the input
if (e.target === inputRef.current) {
if (e.target === keyDownTarget.current) {
e.stopImmediatePropagation();
if (state.focusedNodeId == null) {
collectionRef.current?.dispatchEvent(
Expand All @@ -248,7 +247,7 @@ export function UNSTABLE_useAutocomplete(props: AriaAutocompleteOptions, state:
return () => {
document.removeEventListener('keyup', onKeyUpCapture, true);
};
}, [inputRef, onKeyUpCapture]);
}, [onKeyUpCapture]);

let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/autocomplete');
let collectionProps = useLabels({
Expand Down
8 changes: 4 additions & 4 deletions packages/@react-types/color/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ export interface ColorFieldProps extends Omit<ValueBase<string | Color | null>,
onChange?: (color: Color | null) => void
}

export interface AriaColorFieldProps extends ColorFieldProps, AriaLabelingProps, FocusableDOMProps, Omit<TextInputDOMProps, 'minLength' | 'maxLength' | 'pattern' | 'type' | 'inputMode' | 'autoComplete'>, AriaValidationProps {
export interface AriaColorFieldProps extends ColorFieldProps, AriaLabelingProps, FocusableDOMProps, Omit<TextInputDOMProps, 'minLength' | 'maxLength' | 'pattern' | 'type' | 'inputMode' | 'autoComplete' | 'autoCorrect' | 'spellCheck'>, AriaValidationProps {
/** Enables or disables changing the value with scroll. */
isWheelDisabled?: boolean
}

export interface SpectrumColorFieldProps extends SpectrumTextInputBase, Omit<AriaColorFieldProps, 'isInvalid' | 'validationState'>, SpectrumFieldValidation<Color | null>, SpectrumLabelableProps, StyleProps {
/**
* The color channel that this field edits. If not provided,
* The color channel that this field edits. If not provided,
* the color is edited as a hex value.
*/
channel?: ColorChannel,
Expand Down Expand Up @@ -160,7 +160,7 @@ export interface SpectrumColorWheelProps extends AriaColorWheelProps, Omit<Style
}

export interface ColorSliderProps extends Omit<SliderProps<string | Color>, 'minValue' | 'maxValue' | 'step' | 'pageSize' | 'onChange' | 'onChangeEnd'> {
/**
/**
* The color space that the slider operates in. The `channel` must be in this color space.
* If not provided, this defaults to the color space of the `color` or `defaultColor` value.
*/
Expand All @@ -183,7 +183,7 @@ export interface SpectrumColorSliderProps extends AriaColorSliderProps, StylePro
}

export interface ColorAreaProps extends Omit<ValueBase<string | Color>, 'onChange'> {
/**
/**
* The color space that the color area operates in. The `xChannel` and `yChannel` must be in this color space.
* If not provided, this defaults to the color space of the `color` or `defaultColor` value.
*/
Expand Down
6 changes: 1 addition & 5 deletions packages/react-aria-components/src/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import {AriaAutocompleteProps, CollectionOptions, UNSTABLE_useAutocomplete} from '@react-aria/autocomplete';
import {AutocompleteState, UNSTABLE_useAutocompleteState} from '@react-stately/autocomplete';
import {InputContext} from './Input';
import {mergeProps} from '@react-aria/utils';
import {Provider, removeDataAttributes, SlotProps, SlottedContextValue, useSlottedContext} from './utils';
import React, {createContext, RefObject, useRef} from 'react';
Expand Down Expand Up @@ -42,7 +41,6 @@ export function UNSTABLE_Autocomplete(props: AutocompleteProps) {
let {filter} = props;
let state = UNSTABLE_useAutocompleteState(props);
let collectionRef = useRef<HTMLElement>(null);
let inputRef = useRef<HTMLInputElement>(null);

let {
textFieldProps,
Expand All @@ -52,8 +50,7 @@ export function UNSTABLE_Autocomplete(props: AutocompleteProps) {
} = UNSTABLE_useAutocomplete({
...removeDataAttributes(props),
filter,
collectionRef,
inputRef
collectionRef
}, state);

return (
Expand All @@ -62,7 +59,6 @@ export function UNSTABLE_Autocomplete(props: AutocompleteProps) {
[UNSTABLE_AutocompleteStateContext, state],
[SearchFieldContext, textFieldProps],
[TextFieldContext, textFieldProps],
[InputContext, {ref: inputRef}],
[UNSTABLE_InternalAutocompleteContext, {
filterFn,
collectionProps,
Expand Down

0 comments on commit 8f42edb

Please sign in to comment.