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

fix(autocomplete): fix controlled open state #767

Merged

Conversation

masoudmanson
Copy link
Contributor

@masoudmanson masoudmanson commented May 2, 2024

Summary

Autocomplete
Github issue: #766

This PR addresses issue #766 by fixing the controlled open state behavior of the Autocomplete component for both single and multi-column Autocompletes.

Changes Made

  • Implemented a fix for the controlled open state behavior.
  • Added handlers for both opening and closing the Autocomplete component.
  • Demonstrated the usage of controlled open state with a simple example in the storybook (Autocomplete/Controlled Open Story)

Usage Example

A controlled open state for an Autocomplete that is opened by default can be demonstrated as follows:

const [open, setOpen] = React.useState(true);

<Autocomplete
  // Handles Autocomplete close
  onClickAway={() => {
    setOpen(false);
  }}
  
  // Handles Autocomplete Open
  onClick={() => {
    if (open) {
      setOpen(false);
    } else {
      setOpen(true);
    }
  }}
  
  // The controlled open state
  open={open}
  
  // ... Rest of the Autocomplete Props
/>

@masoudmanson masoudmanson linked an issue May 2, 2024 that may be closed by this pull request
@masoudmanson masoudmanson requested a review from tihuan May 2, 2024 21:15
@masoudmanson masoudmanson self-assigned this May 2, 2024
@masoudmanson masoudmanson added Bug Something isn't working Eng Ready for review This PR is ready for review P0 labels May 2, 2024
Copy link
Contributor

@tihuan tihuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks super good, @masoudmanson ! Thanks for the implementation and story update ✨ !!

Copy link
Contributor

@tihuan tihuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will LGTM first, since I have back to back meetings coming up lol Thanks, Masoud!!

@masoudmanson masoudmanson merged commit 6a77a3d into main May 2, 2024
12 checks passed
@masoudmanson masoudmanson deleted the 766-fix-autocomplete-defaultopen-and-open-behaviors branch May 2, 2024 22:21
@masoudmanson masoudmanson removed the Ready for review This PR is ready for review label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Eng P0 Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Autocomplete defaultOpen and open behaviors
2 participants