Skip to content

Commit

Permalink
fix(use-autocomplete): overwrite onKeyDown to prevent meaningless e…
Browse files Browse the repository at this point in the history
…rror msg (#1909) (#2100)
  • Loading branch information
black197 authored Apr 15, 2024
1 parent 25640e4 commit af877f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-years-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/autocomplete": patch
---

Fix #1909 overwrite `onKeyDown` to prevent meaningless error msg
15 changes: 15 additions & 0 deletions packages/components/autocomplete/src/use-autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit af877f7

Please sign in to comment.