fix(use-autocomplete): overwrite onKeyDown to prevent meaningless error msg (#1909) (#2100)

This commit is contained in:
black197 2024-04-15 22:20:03 +08:00 committed by GitHub
parent 25640e42ff
commit af877f7ddb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"@nextui-org/autocomplete": patch
---
Fix #1909 overwrite `onKeyDown` to prevent meaningless error msg

View File

@ -301,6 +301,21 @@ export function useAutocomplete<T extends object>(originalProps: UseAutocomplete
state,
);
// to prevent the error message:
// stopPropagation is now the default behavior for events in React Spectrum.
// You can use continuePropagation() to revert this behavior.
if (inputProps.onKeyDown) {
const originalOnKeyDown = inputProps.onKeyDown;
inputProps.onKeyDown = (e) => {
if ("continuePropagation" in e) {
e.stopPropagation = () => {};
}
return originalOnKeyDown(e);
};
}
const Component = as || "div";
const slots = useMemo(