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

Add ability to remove dropdown items on backspace #283

Merged
merged 1 commit into from
Jun 24, 2016
Merged

Add ability to remove dropdown items on backspace #283

merged 1 commit into from
Jun 24, 2016

Conversation

ianunruh
Copy link
Contributor

@ianunruh ianunruh commented Jun 24, 2016

Fairly simple change that only affects dropdowns with search and multiple. If the dropdown is focused, the search query is empty and backspace is pressed, the most recently selected item will be removed.

@codecov-io
Copy link

codecov-io commented Jun 24, 2016

Current coverage is 85.67%

No coverage report found for master at 65592b2.

Powered by Codecov. Last updated by 65592b2...a0dac2e

@@ -335,6 +340,22 @@ export default class Dropdown extends Component {
}
}

removeItemOnBackspace = (e) => {
debug('remoteItemOnBackspace()')
Copy link
Member

Choose a reason for hiding this comment

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

Typo remote here.

@ianunruh
Copy link
Contributor Author

Thanks for the feedback so far. I'm pretty new to React and ES2015, so my code quality might not be the best :)

@levithomason
Copy link
Member

levithomason commented Jun 24, 2016

We'll need some coverage in order to merge this. Could you write some tests? We can add a new section to Dropdown-test.js for this:

describe('removing items on backspace', () => {
  it('removes the last item when there is no search query', () => {
    // ...
  })
  it('does not remove the last item when there is a search query', () => {
    // ...
  })
  it('does not remove items for multiple dropdowns without search', () => {
    //...
  })
})

Something like this to get started. npm test to get running. I'd suggest flagging your test with .only() so as to not be overwhelmed by the other tests:

describe.only('removing items on backspace', () => {
...

@levithomason
Copy link
Member

Thanks for the feedback so far. I'm pretty new to React and ES2015, so my code quality might not be the best :)

No worries, thoroughly pleased to see this PR. I knew this feature was missing but just didn't have the time to implement it. Will gladly walk you through.

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

spy.should.have.been.calledOnce()
spy.firstCall.args[1].should.deep.equal(expected)
Copy link
Member

Choose a reason for hiding this comment

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

Looks good, can we add a state assertion to ensure the component is being self controlled:

wrapper.should.have.state('value', expected)

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I wonder if it is a deep equality issue. You could try using the getter form of state and then deep equal:

wrapper
  .state('value')
  .should.deep.equal(expected)

If this still gives you troubles, don't worry about adding it, we can iterate on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That did the trick.

@levithomason
Copy link
Member

This is lookin superb, just the one request for a state assertion on the test here https://github.com/TechnologyAdvice/stardust/pull/283#discussion_r68460171 and I think we can merge this guy. Thanks much!

const { multiple, search } = this.props
const { searchQuery, value } = this.state

if (searchQuery || !search || !multiple || !value) return
Copy link
Member

Choose a reason for hiding this comment

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

Found a little bug here. When there are not items left and you hit backspace, this method still calls onChange and setValue. This is because !value here is still true since it is an empty array.

Being that multiple dropdowns have arrays for value we should use _.isEmpty(value) here instead. This will be true if empty, false if there are any items in the array.

@dvdzkwsk
Copy link
Member

👻 looks great

@levithomason levithomason merged commit eda0c55 into Semantic-Org:master Jun 24, 2016
@levithomason
Copy link
Member

Thanks much for the PR @ianunruh. Hope to see more of your great work here.

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

Successfully merging this pull request may close these issues.

4 participants