Skip to content

Commit 603934e

Browse files
sdjustinjSkinnerAtAdobeLFDanLu
authored
fix(#2468): Combobox: onKeyDown event will now be triggered per docs (#2674)
* onKeyDown event will now be triggered per docs * Changes per review feedback Co-authored-by: Justin Skinner <[email protected]> Co-authored-by: Daniel Lu <[email protected]>
1 parent be936ca commit 603934e

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export function useComboBox<T>(props: AriaComboBoxOptions<T>, state: ComboBoxSta
162162
let {labelProps, inputProps, descriptionProps, errorMessageProps} = useTextField({
163163
...props,
164164
onChange: state.setInputValue,
165-
onKeyDown: !isReadOnly && chain(state.isOpen && collectionProps.onKeyDown, onKeyDown),
165+
onKeyDown: !isReadOnly && chain(state.isOpen && collectionProps.onKeyDown, onKeyDown, props.onKeyDown),
166166
onBlur,
167167
value: state.inputValue,
168168
onFocus,

packages/@react-spectrum/combobox/stories/ComboBox.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,8 @@ let CustomValueComboBox = (props) => {
860860
setSelectedKey(key);
861861
};
862862

863+
actions['onKeyDown'] = action('onKeyDown');
864+
863865
return (
864866
<div>
865867
<div>Selected Key: {selectedKey}</div>

packages/@react-spectrum/combobox/test/ComboBox.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ let outerBlur = jest.fn();
3939
let onFocus = jest.fn();
4040
let onBlur = jest.fn();
4141
let onLoadMore = jest.fn();
42+
let onKeyDown = jest.fn();
4243

4344
let defaultProps = {
4445
label: 'Test',
@@ -937,7 +938,7 @@ describe('ComboBox', function () {
937938
});
938939

939940
it('closes menu and resets selected key if allowsCustomValue=true and no item is focused', function () {
940-
let {getByRole, queryByRole} = render(<ExampleComboBox allowsCustomValue selectedKey="2" />);
941+
let {getByRole, queryByRole} = render(<ExampleComboBox allowsCustomValue selectedKey="2" onKeyDown={onKeyDown} />);
941942

942943
let combobox = getByRole('combobox');
943944
act(() => combobox.focus());
@@ -959,6 +960,7 @@ describe('ComboBox', function () {
959960
});
960961

961962
expect(queryByRole('listbox')).toBeNull();
963+
expect(onKeyDown).toHaveBeenCalledTimes(1);
962964
expect(onSelectionChange).toHaveBeenCalledTimes(1);
963965
expect(onSelectionChange).toHaveBeenCalledWith(null);
964966
expect(onOpenChange).toHaveBeenCalledTimes(2);

0 commit comments

Comments
 (0)