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

Refactor Searchbar into Smaller Components #237

Merged
merged 3 commits into from
Jul 29, 2020

Conversation

jestapinski
Copy link
Collaborator

Ecosystem Staging
Prior Branch Ecosystem Staging
Guides Staging

This PR eliminates some building technical debt by splitting the Searchbar component into four components:

  • The main Searchbar parent which acts as an overall controller of the experience
  • CondensedSearchbar which is the magnifying glass to pop-open the searchbar
  • ExpandedSearchbar which is the searchbar open
  • SearchTextInput which is the custom LeafyGreen text input

These were all in one component before and it was getting tricky to manage state and control changes. This approach is much more maintainable and clean! Passing state now also feels more natural as well.

I'll bump the snapshots separately since this is large enough. I looked side by side on this branch versus the old one (and on mobile). The only change is on mobile the magnifying glass while searching is always filled in. This is actually what the design calls for anyway. No other looks or functionality should change.

Copy link
Member

@sophstad sophstad left a comment

Choose a reason for hiding this comment

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

I noticed that closing the search bar on mobile and reopening it preserves the query that was entered previously. This felt a little unexpected, so just wanted to point it out—perhaps Allison has an opinion on it!

`;

const CondensedSearchbar = ({ onExpand }) => (
<ExpandButton aria-label="Open MongoDB Docs Search" onClick={onExpand}>
Copy link
Member

@sophstad sophstad Jul 29, 2020

Choose a reason for hiding this comment

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

Sorry for missing this the first time around, but why is the onClick handler attached here instead of to the ExpandMagnifyingGlass IconButton? Oops, was a bit scrambled. What I meant is: What is the purpose of including the ExpandMagnifyingGlass icon when we are using an IconButton?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah the button wraps around the icon and this is where the click handler is meant to be bound. This actually also increases the radius where a user can click and something can happen as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah! So with the IconButton we pass the Icon as a child. We use styled here because I use it as a selector when styling the ExpandButton. It is really just an Icon but it has to be a styled(Icon) to use the selector as such.

Comment on lines +15 to +16
const SEARCHBAR_DESKTOP_WIDTH = '372px';
const SEARCHBAR_HEIGHT = '36px';
Copy link
Member

Choose a reason for hiding this comment

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

Good call standardizing these 💯

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it was bothering me haha

@jestapinski
Copy link
Collaborator Author

jestapinski commented Jul 29, 2020

I noticed that closing the search bar on mobile and reopening it preserves the query that was entered previously. This felt a little unexpected, so just wanted to point it out—perhaps Allison has an opinion on it!

oh interesting! This is the intended behavior but we could clear out when closed. It might be nice if they close by accident or something to keep the last query

@jestapinski
Copy link
Collaborator Author

Thanks!

@jestapinski jestapinski merged commit ca17694 into mongodb:search-ui Jul 29, 2020
@jestapinski jestapinski deleted the refactor-search-component branch July 29, 2020 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants