Skip to content

Commit

Permalink
[material-ui][Autocomplete] Add defaultMuiPrevented to onKeyDown ty…
Browse files Browse the repository at this point in the history
…pe (#39820)
  • Loading branch information
sai6855 authored Nov 10, 2023
1 parent 05652f6 commit 4398f9b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/mui-material/src/Autocomplete/Autocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ export interface AutocompleteProps<
* @default 'No options'
*/
noOptionsText?: React.ReactNode;
onKeyDown?: (
event: React.KeyboardEvent<HTMLDivElement> & { defaultMuiPrevented?: boolean },
) => void;
/**
* Override the default text for the *open popup* icon button.
*
Expand Down
4 changes: 4 additions & 0 deletions packages/mui-material/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,10 @@ Autocomplete.propTypes /* remove-proptypes */ = {
* @param {string} reason Can be: `"input"` (user input), `"reset"` (programmatic change), `"clear"`.
*/
onInputChange: PropTypes.func,
/**
* @ignore
*/
onKeyDown: PropTypes.func,
/**
* Callback fired when the popup requests to be opened.
* Use in controlled mode (see open).
Expand Down
14 changes: 14 additions & 0 deletions packages/mui-material/src/Autocomplete/Autocomplete.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,17 @@ function CustomListboxRef() {
/>
);
}

// Tests presence of defaultMuiPrevented in event
<Autocomplete
renderInput={(params) => <TextField {...params} />}
options={['one', 'two', 'three']}
onKeyDown={(e) => {
expectType<
React.KeyboardEvent<HTMLDivElement> & {
defaultMuiPrevented?: boolean;
},
typeof e
>(e);
}}
/>;

0 comments on commit 4398f9b

Please sign in to comment.