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

feat(Dropdown): add prop for clearing searchQuery data on item select or on enter #1955

Closed
wants to merge 5 commits into from

Conversation

creedmangrum
Copy link

@creedmangrum creedmangrum commented Aug 11, 2017

I wanted to add a prop to the dropdown where the search query could be cleared after selection on the multiple select, if desired.

This maintains the current behavior of how everything works today, but if the prop is added then the search query will clear after item selection.

I asked this question on issue #1954 but just figured it was easy enough to PR before waiting for an answer.

@codecov-io
Copy link

codecov-io commented Aug 11, 2017

Codecov Report

Merging #1955 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1955      +/-   ##
=========================================
- Coverage    99.8%   99.8%   -0.01%     
=========================================
  Files         148     148              
  Lines        2589    2568      -21     
=========================================
- Hits         2584    2563      -21     
  Misses          5       5
Impacted Files Coverage Δ
src/modules/Dropdown/Dropdown.js 100% <100%> (ø) ⬆️
src/collections/Grid/GridColumn.js 100% <0%> (ø) ⬆️
src/modules/Transition/TransitionGroup.js 100% <0%> (ø) ⬆️
src/modules/Sticky/Sticky.js 100% <0%> (ø) ⬆️
src/modules/Search/Search.js 100% <0%> (ø) ⬆️
src/modules/Tab/Tab.js 100% <0%> (ø) ⬆️
src/elements/Button/Button.js 100% <0%> (ø) ⬆️
src/behaviors/Visibility/Visibility.js 100% <0%> (ø) ⬆️
src/modules/Popup/Popup.js 100% <0%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23ec465...16f44ae. Read the comment docs.

@@ -216,6 +216,9 @@ export interface DropdownProps {
/** A shorthand for a search input. */
searchInput?: any;

/** Whether the searchQuery is cleared or not when selecting an item from search. */
searchQueryClearOnSelect?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could we go with clearSearchQueryOnSelect?

Copy link
Author

Choose a reason for hiding this comment

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

not a nit at all, was hoping for some specific feedback on the naming anyway. i just put it near the search ones as it felt grouped, but really was unsure about naming convention. will switch to your suggestion.

Copy link
Member

@levithomason levithomason left a comment

Choose a reason for hiding this comment

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

I've requested a prop name change above. We just need some tests for this prop:

describe('clearSearchQueryOnSelect', () => {
  it('does not clear the query by default on item click', () => {})
  
  it('does not clear the query by default on enter', () => {})
  
  it('clears the query on item click', () => {})
  
  it('clears the query on enter', () => {})
})

@layershifter layershifter changed the title Adds prop for clearing searchQuery data on item select or on enter Dropdown: add prop for clearing searchQuery data on item select or on enter Aug 14, 2017
@layershifter layershifter changed the title Dropdown: add prop for clearing searchQuery data on item select or on enter feat(Dropdown): add prop for clearing searchQuery data on item select or on enter Aug 14, 2017
@creedmangrum
Copy link
Author

thanks for the feedback. will add the tests and prop name change.

@creedmangrum
Copy link
Author

okay should be good to go!

.simulate('click', nativeEvent)

// cleared search query
wrapper.should.have.state('searchQuery', searchQuery)
Copy link
Member

Choose a reason for hiding this comment

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

Comment needs updated, or removed :)

domEvent.keyDown(document, { key: 'Enter' })

// cleared search query
wrapper.should.have.state('searchQuery', searchQuery)
Copy link
Member

Choose a reason for hiding this comment

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

Comment out of date

Copy link
Member

@levithomason levithomason left a comment

Choose a reason for hiding this comment

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

There are a couple out of date comments that should be updated or removed.

We merge another PR which handles clearing the search query when there is only one option. This PR has some conflicts that need to be resolved.

@creedmangrum
Copy link
Author

Great taken care of. Sorry about the bad comments in the tests. Whoops.

@creedmangrum
Copy link
Author

I think that the other PR that was merged probably solves for the use case, where the search query should be cleared if it is the available options === 1. I am likely going to close this, unless you feel that it still makes sense to do.

@levithomason
Copy link
Member

Fewer options in the Dropdown, the happy I am 😄! This component is quite complex and getting hairy to work on.

Assuming we're all good here, I'll take your suggestion and close this. Let me know if we need to reopen it.

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

Successfully merging this pull request may close these issues.

4 participants