From 22321d00ed91d4d9d3faaf84c6b438084ff160a8 Mon Sep 17 00:00:00 2001 From: Adrian Estevez Date: Fri, 4 Nov 2022 09:33:04 -0400 Subject: [PATCH 1/6] fix: onFocus and onClick in Picklist triggered when it should not --- src/components/Picklist/index.js | 14 ++++++++------ src/components/Picklist/readme.md | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/Picklist/index.js b/src/components/Picklist/index.js index c8dfa4d9d..bf37ba091 100644 --- a/src/components/Picklist/index.js +++ b/src/components/Picklist/index.js @@ -157,19 +157,22 @@ class Picklist extends Component { } handleInputClick(event) { - const { onClick } = this.props; const { isOpen } = this.state; - onClick(event); if (isOpen) { return this.closeMenu(); } + const { onClick } = this.props; + onClick(event); return this.openMenu(); } handleFocus() { - const { onFocus, value } = this.props; - const eventValue = value || null; - onFocus(eventValue); + const { isOpen } = this.state; + if (!isOpen) { + const { onFocus, value } = this.props; + const eventValue = value || null; + onFocus(eventValue); + } } handleBlur() { @@ -185,7 +188,6 @@ class Picklist extends Component { const { label, name, icon, value } = option; this.closeMenu(); setTimeout(() => { - this.focus(); return onChange({ label, name, icon, value }); }, 0); } diff --git a/src/components/Picklist/readme.md b/src/components/Picklist/readme.md index e474acd5c..fd17d0d68 100644 --- a/src/components/Picklist/readme.md +++ b/src/components/Picklist/readme.md @@ -58,6 +58,8 @@ const initialState = { value: null }; placeholder="Choose Building" onChange={value => setState({ value })} value={state.value} + onClick={() => console.log('click')} + onFocus={() => console.log('focus')} label="Select Building" hideLabel enableSearch From 8bcd692ca572914a5919dcc8828cbb49481b065f Mon Sep 17 00:00:00 2001 From: Adrian Estevez Date: Fri, 4 Nov 2022 14:06:06 -0400 Subject: [PATCH 2/6] fix: onFocus and onClick in Picklist triggered when it should not --- src/components/Picklist/readme.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/Picklist/readme.md b/src/components/Picklist/readme.md index fd17d0d68..e474acd5c 100644 --- a/src/components/Picklist/readme.md +++ b/src/components/Picklist/readme.md @@ -58,8 +58,6 @@ const initialState = { value: null }; placeholder="Choose Building" onChange={value => setState({ value })} value={state.value} - onClick={() => console.log('click')} - onFocus={() => console.log('focus')} label="Select Building" hideLabel enableSearch From d82e06f3cd6f6affdda84d9a194394f10331136f Mon Sep 17 00:00:00 2001 From: Adrian Estevez Date: Sun, 6 Nov 2022 19:10:20 -0500 Subject: [PATCH 3/6] add test --- src/components/Picklist/__test__/picklist.spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/components/Picklist/__test__/picklist.spec.js b/src/components/Picklist/__test__/picklist.spec.js index 0e54f660f..6f1d9b5ca 100644 --- a/src/components/Picklist/__test__/picklist.spec.js +++ b/src/components/Picklist/__test__/picklist.spec.js @@ -193,4 +193,19 @@ describe('', () => { component.unmount(); expect(mockStopListening).toHaveBeenCalled(); }); + it('should handle onClick and onFocus just one time', () => { + const component = mount( + + + + + , + ); + const input = component.find('input'); + input.simulate('click'); + input.simulate('focus'); + input.simulate('click'); + input.simulate('focus'); + expect(mockStartListening).toHaveBeenCalledTimes(1); + }); }); From 0b0a92ce85f7897ad35be27b9ca347ce544e965f Mon Sep 17 00:00:00 2001 From: Adrian Estevez Date: Mon, 12 Dec 2022 22:27:56 -0500 Subject: [PATCH 4/6] fix: onFocus and onClick in Picklist triggered when it should not --- src/components/Picklist/__test__/picklist.spec.js | 15 --------------- src/components/Picklist/index.js | 4 ++-- src/components/Picklist/readme.md | 2 ++ 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/components/Picklist/__test__/picklist.spec.js b/src/components/Picklist/__test__/picklist.spec.js index 6f1d9b5ca..0e54f660f 100644 --- a/src/components/Picklist/__test__/picklist.spec.js +++ b/src/components/Picklist/__test__/picklist.spec.js @@ -193,19 +193,4 @@ describe('', () => { component.unmount(); expect(mockStopListening).toHaveBeenCalled(); }); - it('should handle onClick and onFocus just one time', () => { - const component = mount( - - - - - , - ); - const input = component.find('input'); - input.simulate('click'); - input.simulate('focus'); - input.simulate('click'); - input.simulate('focus'); - expect(mockStartListening).toHaveBeenCalledTimes(1); - }); }); diff --git a/src/components/Picklist/index.js b/src/components/Picklist/index.js index 0c651d13a..df0a696fd 100644 --- a/src/components/Picklist/index.js +++ b/src/components/Picklist/index.js @@ -157,12 +157,12 @@ class Picklist extends Component { } handleInputClick(event) { + const { onClick } = this.props; const { isOpen } = this.state; + onClick(event); if (isOpen) { return this.closeMenu(); } - const { onClick } = this.props; - onClick(event); return this.openMenu(); } diff --git a/src/components/Picklist/readme.md b/src/components/Picklist/readme.md index 0db1ca5cf..bcda068c5 100644 --- a/src/components/Picklist/readme.md +++ b/src/components/Picklist/readme.md @@ -22,6 +22,8 @@ const initialState = { value: { name: 'option 3', label: 'Central Park' } }; onChange={value => setState({ value })} value={state.value} label="Select Building" + onClick={() => console.log('click')} + onFocus={() => console.log('focus')} hideLabel >