Skip to content

Commit 93b3c95

Browse files
joshuajacosnowystingerLFDanLuktabors
authored
Narrow combobox focus event handler types (#4039)
Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Daniel Lu <[email protected]> Co-authored-by: Kyle Taborski <[email protected]>
1 parent b075dc5 commit 93b3c95

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

packages/@react-aria/combobox/src/useComboBox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function useComboBox<T>(props: AriaComboBoxOptions<T>, state: ComboBoxSta
141141
}
142142
};
143143

144-
let onBlur = (e: FocusEvent) => {
144+
let onBlur = (e: FocusEvent<HTMLInputElement>) => {
145145
// Ignore blur if focused moved to the button or into the popover.
146146
if (e.relatedTarget === buttonRef?.current || popoverRef.current?.contains(e.relatedTarget)) {
147147
return;
@@ -154,7 +154,7 @@ export function useComboBox<T>(props: AriaComboBoxOptions<T>, state: ComboBoxSta
154154
state.setFocused(false);
155155
};
156156

157-
let onFocus = (e: FocusEvent) => {
157+
let onFocus = (e: FocusEvent<HTMLInputElement>) => {
158158
if (state.isFocused) {
159159
return;
160160
}

packages/@react-types/combobox/src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {AriaLabelingProps, AsyncLoadable, CollectionBase, DOMProps, FocusablePro
1414

1515
export type MenuTriggerAction = 'focus' | 'input' | 'manual';
1616

17-
export interface ComboBoxProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection'>, InputBase, TextInputBase, Validation, FocusableProps, LabelableProps, HelpTextProps {
17+
export interface ComboBoxProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection'>, InputBase, TextInputBase, Validation, FocusableProps<HTMLInputElement>, LabelableProps, HelpTextProps {
1818
/** The list of ComboBox items (uncontrolled). */
1919
defaultItems?: Iterable<T>,
2020
/** The list of ComboBox items (controlled). */

packages/@react-types/shared/src/events.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ export interface KeyboardEvents {
6868
onKeyUp?: (e: KeyboardEvent) => void
6969
}
7070

71-
export interface FocusEvents {
71+
export interface FocusEvents<Target = Element> {
7272
/** Handler that is called when the element receives focus. */
73-
onFocus?: (e: FocusEvent) => void,
73+
onFocus?: (e: FocusEvent<Target>) => void,
7474
/** Handler that is called when the element loses focus. */
75-
onBlur?: (e: FocusEvent) => void,
75+
onBlur?: (e: FocusEvent<Target>) => void,
7676
/** Handler that is called when the element's focus status changes. */
7777
onFocusChange?: (isFocused: boolean) => void
7878
}
@@ -105,7 +105,7 @@ export interface PressEvents {
105105
onPressUp?: (e: PressEvent) => void
106106
}
107107

108-
export interface FocusableProps extends FocusEvents, KeyboardEvents {
108+
export interface FocusableProps<Target = Element> extends FocusEvents<Target>, KeyboardEvents {
109109
/** Whether the element should receive focus on render. */
110110
autoFocus?: boolean
111111
}

0 commit comments

Comments
 (0)