Skip to content

Commit 7048d9e

Browse files
committed
PickList on click flick fix on click
1 parent 4b71fa1 commit 7048d9e

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

components/SLDSPicklistBase/index.jsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ module.exports = React.createClass( {
3434
className:'',
3535
listClassName:'',
3636
onClick () {
37-
console.log('onClick should be defined');
3837
},
3938
onSelect (value){
4039
console.log('onItemSelect should be defined');
@@ -96,14 +95,22 @@ module.exports = React.createClass( {
9695
},
9796

9897
handleClick(event) {
99-
event.preventDefault();
100-
event.stopPropagation();
101-
this.setState({isOpen:true});
102-
if(this.props.onClick){
103-
this.props.onClick();
98+
EventUtil.trap(event);
99+
if(!this.state.isOpen){
100+
this.setState({isOpen:true});
101+
if(this.props.onClick){
102+
this.props.onClick();
103+
}
104+
}
105+
else{
106+
this.handleClose();
104107
}
105108
},
106109

110+
handleMouseDown(event){
111+
EventUtil.trapImmediate(event);
112+
},
113+
107114
handleBlur(e) {
108115
this.setState({isFocused:false});
109116
},
@@ -128,10 +135,12 @@ module.exports = React.createClass( {
128135
event.keyCode === KEYS.DOWN ||
129136
event.keyCode === KEYS.UP){
130137
EventUtil.trapEvent(event);
138+
131139
this.setState({
132140
isOpen:true,
133141
highlightedIndex:0
134142
});
143+
135144
}
136145
}
137146
},
@@ -205,7 +214,7 @@ module.exports = React.createClass( {
205214
let className = this.state.currentSelectedItem? 'slds-input--bare slds-hide':'slds-input--bare';
206215
return (
207216

208-
<div className={"slds-form-element ignore-react-onclickoutside slds-theme--"+this.props.theme}>
217+
<div className={"slds-form-element slds-theme--"+this.props.theme}>
209218
<div className={"slds-picklist slds-theme--"+this.props.theme}>
210219
<form>
211220
<button
@@ -216,6 +225,7 @@ module.exports = React.createClass( {
216225
onBlur={this.handleBlur}
217226
onFocus={this.handleFocus}
218227
onClick={this.handleClick}
228+
onMouseDown={this.handleMouseDown}
219229
tabIndex={this.state.isOpen?-1:0}
220230
onKeyDown={this.handleKeyDown} >
221231
<span className="slds-truncate">{this.getPlaceholder()}</span>
@@ -232,6 +242,7 @@ module.exports = React.createClass( {
232242
},
233243

234244
componentDidUpdate( prevProps, prevState) {
245+
235246
if(this.state.lastBlurredTimeStamp !== prevState.lastBlurredTimeStamp){
236247
if(this.state.lastBlurredIndex === this.state.highlightedIndex){
237248
this.handleClose();
@@ -254,9 +265,11 @@ module.exports = React.createClass( {
254265
}
255266
}
256267

268+
257269
if(this.props.value !== prevProps.value){
258270
this.handleSelect(this.getIndexByValue(this.props.value));
259271
}
272+
260273
},
261274

262275
});

components/utils/EventUtil.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ const EventUtil = {
2424

2525
trap(event){
2626
return EventUtil.trapEvent( event );
27+
},
28+
29+
trapImmediate(event){
30+
if(event.nativeEvent){
31+
event.nativeEvent.stopImmediatePropagation();
32+
}
33+
EventUtil.trap(event);
2734
}
2835

2936
};

0 commit comments

Comments
 (0)