Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete does not blur when selecting item #3379

Closed
kamami opened this issue Jun 30, 2024 · 5 comments
Closed

Autocomplete does not blur when selecting item #3379

kamami opened this issue Jun 30, 2024 · 5 comments

Comments

@kamami
Copy link

kamami commented Jun 30, 2024

NextUI Version

2.4.2

Describe the bug

Input of Autocomplete component does not blur when selecting an item from the popover. Using a ref in inputProps to blur manually throws an error when hovering over the popover.

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

Just test the example in the docs. There it is also not blurring the input.

Expected behavior

I would expect that the input of Autocomplete gets blurred when selecting an item from the popover.

Screenshots or Videos

No response

Operating System Version

macOs

Browser

Chrome

Copy link

linear bot commented Jun 30, 2024

@wingkwong
Copy link
Member

That's by design.

@wingkwong wingkwong closed this as not planned Won't fix, can't repro, duplicate, stale Jul 1, 2024
@kamami
Copy link
Author

kamami commented Jul 1, 2024

But how can this be then achieved? I can not pass a ref to the input.

@wingkwong
Copy link
Member

you may pass the ref to autocomplete component instead of passing to inputProps. The ref will be forwarded to input.

<Autocomplete ref={ref}> 
...
</Autocomplete>

@kamami
Copy link
Author

kamami commented Jul 1, 2024

I tired it an this makes things even worse. With this the input does not blur neither and the popover does not even disappear.

Bildschirmaufnahme.2024-07-01.um.10.23.32.mov

This is the code:

export default function Search({ nodes, setNodes }) {
  const inputRef = useRef(null);

  return (
    <Autocomplete
      ref={inputRef}
      label="Suche"
      placeholder="Suche eine Person"
      onSelectionChange={(key) => {
        if (inputRef.current) {
          inputRef.current.blur();
        }
      }}
    >
      {nodes.map((person) => (
        <AutocompleteItem key={person.id} value={person.id}>
          {person.data.label}
        </AutocompleteItem>
      ))}
    </Autocomplete>
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants