diff --git a/.all-contributorsrc b/.all-contributorsrc index 993a0816b..648bbbce2 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -481,7 +481,8 @@ "avatar_url": "https://avatars3.githubusercontent.com/u/8997319?v=4", "profile": "https://alexandernanberg.com", "contributions": [ - "doc" + "doc", + "code" ] }, { diff --git a/README.md b/README.md index 5375ea01a..6304b7fbb 100644 --- a/README.md +++ b/README.md @@ -1014,7 +1014,7 @@ Thanks goes to these people ([emoji key][emojis]): | [
Matt Parrish](https://github.com/pbomb)
[πŸ”§](#tool-pbomb "Tools") [πŸ‘€](#review-pbomb "Reviewed Pull Requests") | [
thom](http://thom.kr)
[πŸ’»](https://github.com/paypal/downshift/commits?author=thomhos "Code") | [
Vu Tran](http://twitter.com/tranvu)
[πŸ’»](https://github.com/paypal/downshift/commits?author=vutran "Code") | [
Codie Mullins](https://github.com/codiemullins)
[πŸ’»](https://github.com/paypal/downshift/commits?author=codiemullins "Code") [πŸ’‘](#example-codiemullins "Examples") | [
Mohammad Rajabifard](https://morajabi.me)
[πŸ“–](https://github.com/paypal/downshift/commits?author=morajabi "Documentation") [πŸ€”](#ideas-morajabi "Ideas, Planning, & Feedback") | [
Frank Tan](https://github.com/tansongyang)
[πŸ’»](https://github.com/paypal/downshift/commits?author=tansongyang "Code") | [
Kier Borromeo](https://kierb.com)
[πŸ’‘](#example-srph "Examples") | | [
Paul Veevers](https://github.com/paul-veevers)
[πŸ’»](https://github.com/paypal/downshift/commits?author=paul-veevers "Code") | [
Ron Cruz](https://github.com/Ronolibert)
[πŸ“–](https://github.com/paypal/downshift/commits?author=Ronolibert "Documentation") | [
Rick McGavin](http://rickmcgavin.github.io)
[πŸ“–](https://github.com/paypal/downshift/commits?author=rickMcGavin "Documentation") | [
Jelle Versele](http://twitter.com/vejersele)
[πŸ’‘](#example-vejersele "Examples") | [
Brent Ertz](https://github.com/brentertz)
[πŸ€”](#ideas-brentertz "Ideas, Planning, & Feedback") | [
Justice Mba ](https://github.com/Dajust)
[πŸ’»](https://github.com/paypal/downshift/commits?author=Dajust "Code") [πŸ“–](https://github.com/paypal/downshift/commits?author=Dajust "Documentation") [πŸ€”](#ideas-Dajust "Ideas, Planning, & Feedback") | [
Mark Ellis](http://mfellis.com)
[πŸ€”](#ideas-ellismarkf "Ideas, Planning, & Feedback") | | [
us͑an̸df͘rien͜ds͠](http://ronak.io/)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ausandfriends "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=usandfriends "Code") [⚠️](https://github.com/paypal/downshift/commits?author=usandfriends "Tests") | [
Robin Drexler](https://www.robin-drexler.com/)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Arobin-drexler "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=robin-drexler "Code") | [
Arturo Romero](http://arturoromero.info/)
[πŸ’‘](#example-arturoromeroslc "Examples") | [
yp](http://algolab.eu/pirola)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ayp "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=yp "Code") [⚠️](https://github.com/paypal/downshift/commits?author=yp "Tests") | [
Dave Garwacke](http://www.warbyparker.com)
[πŸ“–](https://github.com/paypal/downshift/commits?author=ifyoumakeit "Documentation") | [
Ivan Pazhitnykh](http://linkedin.com/in/drapegnik)
[πŸ’»](https://github.com/paypal/downshift/commits?author=Drapegnik "Code") [⚠️](https://github.com/paypal/downshift/commits?author=Drapegnik "Tests") | [
Luis Merino](https://github.com/Rendez)
[πŸ“–](https://github.com/paypal/downshift/commits?author=Rendez "Documentation") | -| [
Andrew Hansen](http://twitter.com/arahansen)
[πŸ’»](https://github.com/paypal/downshift/commits?author=arahansen "Code") [⚠️](https://github.com/paypal/downshift/commits?author=arahansen "Tests") [πŸ€”](#ideas-arahansen "Ideas, Planning, & Feedback") | [
John Whiles](http://www.johnwhiles.com)
[πŸ’»](https://github.com/paypal/downshift/commits?author=Jwhiles "Code") | [
Justin Hall](https://github.com/wKovacs64)
[πŸš‡](#infra-wKovacs64 "Infrastructure (Hosting, Build-Tools, etc)") | [
Pete NykΓ€nen](https://twitter.com/pete_tnt)
[πŸ‘€](#review-petetnt "Reviewed Pull Requests") | [
Jared Palmer](http://jaredpalmer.com)
[πŸ’»](https://github.com/paypal/downshift/commits?author=jaredpalmer "Code") | [
Philip Young](http://www.philipyoungg.com)
[πŸ’»](https://github.com/paypal/downshift/commits?author=philipyoungg "Code") [⚠️](https://github.com/paypal/downshift/commits?author=philipyoungg "Tests") [πŸ€”](#ideas-philipyoungg "Ideas, Planning, & Feedback") | [
Alexander Nanberg](https://alexandernanberg.com)
[πŸ“–](https://github.com/paypal/downshift/commits?author=alexandernanberg "Documentation") | +| [
Andrew Hansen](http://twitter.com/arahansen)
[πŸ’»](https://github.com/paypal/downshift/commits?author=arahansen "Code") [⚠️](https://github.com/paypal/downshift/commits?author=arahansen "Tests") [πŸ€”](#ideas-arahansen "Ideas, Planning, & Feedback") | [
John Whiles](http://www.johnwhiles.com)
[πŸ’»](https://github.com/paypal/downshift/commits?author=Jwhiles "Code") | [
Justin Hall](https://github.com/wKovacs64)
[πŸš‡](#infra-wKovacs64 "Infrastructure (Hosting, Build-Tools, etc)") | [
Pete NykΓ€nen](https://twitter.com/pete_tnt)
[πŸ‘€](#review-petetnt "Reviewed Pull Requests") | [
Jared Palmer](http://jaredpalmer.com)
[πŸ’»](https://github.com/paypal/downshift/commits?author=jaredpalmer "Code") | [
Philip Young](http://www.philipyoungg.com)
[πŸ’»](https://github.com/paypal/downshift/commits?author=philipyoungg "Code") [⚠️](https://github.com/paypal/downshift/commits?author=philipyoungg "Tests") [πŸ€”](#ideas-philipyoungg "Ideas, Planning, & Feedback") | [
Alexander Nanberg](https://alexandernanberg.com)
[πŸ“–](https://github.com/paypal/downshift/commits?author=alexandernanberg "Documentation") [πŸ’»](https://github.com/paypal/downshift/commits?author=alexandernanberg "Code") | | [
Pete Redmond](https://httpete.com)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ahttpete-ire "Bug reports") | [
Nick Lavin](https://github.com/Zashy)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3AZashy "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=Zashy "Code") [⚠️](https://github.com/paypal/downshift/commits?author=Zashy "Tests") | [
James Long](http://jlongster.com)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ajlongster "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=jlongster "Code") | [
Michael Ball](http://michaelball.co)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Acycomachead "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=cycomachead "Code") [⚠️](https://github.com/paypal/downshift/commits?author=cycomachead "Tests") | [
CAVALEIRO Julien](https://github.com/Julienng)
[πŸ’‘](#example-Julienng "Examples") | [
Kim GrΓΆnqvist](http://www.kimgronqvist.se)
[πŸ’»](https://github.com/paypal/downshift/commits?author=kimgronqvist "Code") [⚠️](https://github.com/paypal/downshift/commits?author=kimgronqvist "Tests") | [
Sijie](http://sijietian.com)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Atiansijie "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=tiansijie "Code") | | [
Dony Sukardi](http://dsds.io)
[πŸ’‘](#example-donysukardi "Examples") [πŸ’¬](#question-donysukardi "Answering Questions") [πŸ’»](https://github.com/paypal/downshift/commits?author=donysukardi "Code") [⚠️](https://github.com/paypal/downshift/commits?author=donysukardi "Tests") | [
Dillon Mulroy](https://dillonmulroy.com)
[πŸ“–](https://github.com/paypal/downshift/commits?author=dmmulroy "Documentation") | [
Curtis Tate Wilkinson](https://twitter.com/curtytate)
[πŸ’»](https://github.com/paypal/downshift/commits?author=curtiswilkinson "Code") | [
Brice BERNARD](https://github.com/brikou)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Abrikou "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=brikou "Code") | [
Tony Xu](https://github.com/xutopia)
[πŸ’»](https://github.com/paypal/downshift/commits?author=xutopia "Code") | [
Anthony Ng](http://anthonyng.me)
[πŸ“–](https://github.com/paypal/downshift/commits?author=newyork-anthonyng "Documentation") | [
S S](https://github.com/notruth)
[πŸ’¬](#question-notruth "Answering Questions") [πŸ’»](https://github.com/paypal/downshift/commits?author=notruth "Code") [πŸ“–](https://github.com/paypal/downshift/commits?author=notruth "Documentation") [πŸ€”](#ideas-notruth "Ideas, Planning, & Feedback") [⚠️](https://github.com/paypal/downshift/commits?author=notruth "Tests") | | [
Austin Tackaberry](http://austintackaberry.co)
[πŸ’¬](#question-austintackaberry "Answering Questions") [πŸ’»](https://github.com/paypal/downshift/commits?author=austintackaberry "Code") [πŸ“–](https://github.com/paypal/downshift/commits?author=austintackaberry "Documentation") [πŸ›](https://github.com/paypal/downshift/issues?q=author%3Aaustintackaberry "Bug reports") [πŸ’‘](#example-austintackaberry "Examples") [πŸ€”](#ideas-austintackaberry "Ideas, Planning, & Feedback") [πŸ‘€](#review-austintackaberry "Reviewed Pull Requests") [⚠️](https://github.com/paypal/downshift/commits?author=austintackaberry "Tests") | [
Jean Duthon](https://github.com/jduthon)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ajduthon "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=jduthon "Code") | [
Anton Telesh](http://antontelesh.github.io)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3AAntontelesh "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=Antontelesh "Code") | [
Eric Edem](https://github.com/ericedem)
[πŸ’»](https://github.com/paypal/downshift/commits?author=ericedem "Code") [πŸ“–](https://github.com/paypal/downshift/commits?author=ericedem "Documentation") [πŸ€”](#ideas-ericedem "Ideas, Planning, & Feedback") [⚠️](https://github.com/paypal/downshift/commits?author=ericedem "Tests") | [
Austin Wood](https://github.com/indiesquidge)
[πŸ’¬](#question-indiesquidge "Answering Questions") [πŸ“–](https://github.com/paypal/downshift/commits?author=indiesquidge "Documentation") [πŸ‘€](#review-indiesquidge "Reviewed Pull Requests") | [
Mark Murray](https://github.com/mmmurray)
[πŸš‡](#infra-mmmurray "Infrastructure (Hosting, Build-Tools, etc)") | [
Gianmarco](https://github.com/gsimone)
[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Agsimone "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=gsimone "Code") | diff --git a/src/__tests__/downshift.lifecycle.js b/src/__tests__/downshift.lifecycle.js index d9d1ab740..0095e3855 100644 --- a/src/__tests__/downshift.lifecycle.js +++ b/src/__tests__/downshift.lifecycle.js @@ -7,6 +7,30 @@ import * as utils from '../utils' jest.useFakeTimers() jest.mock('../set-a11y-status') +test('do not set state after unmount', () => { + const handleStateChange = jest.fn() + const childrenSpy = jest.fn(({getInputProps}) => ( +
+ + +
+ )) + const MyComponent = () => ( + {childrenSpy} + ) + const {queryByTestId, container, unmount} = render() + const button = queryByTestId('button') + document.body.appendChild(container) + + // blur toggle button + Simulate.blur(button) + handleStateChange.mockClear() + + // unmount + unmount() + expect(handleStateChange).toHaveBeenCalledTimes(0) +}) + test('handles mouse events properly to reset state', () => { const handleStateChange = jest.fn() const childrenSpy = jest.fn(({getInputProps}) => ( diff --git a/src/downshift.js b/src/downshift.js index 0f3bdda24..f5d3ed9c8 100644 --- a/src/downshift.js +++ b/src/downshift.js @@ -302,6 +302,9 @@ class Downshift extends Component { // In addition, we'll call this.props.onChange if the // selectedItem is changed. internalSetState = (stateToSet, cb) => { + // Prevent setState on unmounted components. + if (!this._isMounted) return undefined + let isItemSelected, onChangeArg const onStateChangeArg = {}