Skip to content

Commit 713f3c1

Browse files
committed
Merge pull request #4 from sfdc-matrix/UpdatePicklist
Use PropTypes for PicklistBase Function
2 parents 9d15793 + 6038c00 commit 713f3c1

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

components/SLDSPicklistBase/index.jsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
99

1010
'use strict';
1111

12-
import React from 'react';
12+
import React, {PropTypes} from 'react';
1313
import SLDSPopover from '../SLDSPopover';
1414
import List from './list';
1515

@@ -21,6 +21,12 @@ import {KEYS,EventUtil} from '../utils';
2121

2222
module.exports = React.createClass( {
2323

24+
propTypes : {
25+
onClick: PropTypes.func,
26+
onSelect: PropTypes.func.isRequired,
27+
onUpdateHighlighted: PropTypes.func
28+
},
29+
2430
getDefaultProps(){
2531
return {
2632
placeholder: 'Select an Option',
@@ -32,15 +38,7 @@ module.exports = React.createClass( {
3238
initialFocus: false,
3339
modal: false,
3440
className:'',
35-
listClassName:'',
36-
onClick () {
37-
},
38-
onSelect (value){
39-
console.log('onItemSelect should be defined');
40-
},
41-
onUpdateHighlighted (nextIndex) {
42-
console.log('onUpdateHighlighted should be defined');
43-
}
41+
listClassName:''
4442
}
4543
},
4644

@@ -130,9 +128,9 @@ module.exports = React.createClass( {
130128

131129
handleKeyDown(event) {
132130
if (event.keyCode){
133-
if (event.keyCode === KEYS.ENTER ||
134-
event.keyCode === KEYS.SPACE ||
135-
event.keyCode === KEYS.DOWN ||
131+
if (event.keyCode === KEYS.ENTER ||
132+
event.keyCode === KEYS.SPACE ||
133+
event.keyCode === KEYS.DOWN ||
136134
event.keyCode === KEYS.UP){
137135
EventUtil.trapEvent(event);
138136

@@ -165,8 +163,8 @@ module.exports = React.createClass( {
165163
className={this.props.listClassName}
166164
highlightedIndex={this.state.highlightedIndex}
167165
selectedIndex={this.state.selectedIndex}
168-
onSelect={this.handleSelect}
169-
onUpdateHighlighted={this.handleUpdateHighlighted}
166+
onSelect={this.handleSelect}
167+
onUpdateHighlighted={this.handleUpdateHighlighted}
170168
onListBlur={this.handleListBlur}
171169
onListItemBlur={this.handleListItemBlur}
172170
onCancel={this.handleCancel}
@@ -176,9 +174,9 @@ module.exports = React.createClass( {
176174
getSimplePopover() {
177175
return (
178176
!this.props.disabled && this.state.isOpen?
179-
<div
180-
className="slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu"
181-
targetElement={this.refs.button}
177+
<div
178+
className="slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu"
179+
targetElement={this.refs.button}
182180
style={{maxHeight:'20em'}}>
183181
{this.getPopoverContent()}
184182
</div>:null
@@ -188,9 +186,9 @@ module.exports = React.createClass( {
188186
getModalPopover() {
189187
return (
190188
!this.props.disabled && this.state.isOpen?
191-
<SLDSPopover
192-
className='slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu'
193-
targetElement={this.refs.date}
189+
<SLDSPopover
190+
className='slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu'
191+
targetElement={this.refs.date}
194192
closeOnTabKey={true}
195193
onClose={this.handleCancel}>
196194
{this.getPopoverContent()}
@@ -217,7 +215,7 @@ module.exports = React.createClass( {
217215
<div className={"slds-form-element slds-theme--"+this.props.theme}>
218216
<div className={"slds-picklist slds-theme--"+this.props.theme}>
219217
<form>
220-
<button
218+
<button
221219
id={this.props.id}
222220
ref="button"
223221
className={'slds-button slds-button--neutral slds-picklist__label '+this.props.className }

demo/pages/HomePage/PicklistBaseSection.jsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ module.exports = React.createClass( {
2828
return {};
2929
},
3030

31+
handleOnUpdateHighlighted () {
32+
console.log('onUpdateHighlighted should be defined');
33+
},
34+
35+
handleOnSelect() {
36+
console.log('onSelect should be defined');
37+
},
38+
39+
handleOnClick() {
40+
console.log('onClick should be defined');
41+
},
3142

3243
render() {
3344
return (
@@ -57,12 +68,14 @@ module.exports = React.createClass( {
5768
{label:'D2 Option',value:'D1'},
5869
{label:'E2 Option Super Super Long',value:'E1'},
5970

60-
6171
]}
6272
value='C0'
6373
label="Contacts"
6474
modal={false}
65-
placeholder = "Select a contact" />
75+
placeholder = "Select a contact"
76+
onSelect={this.handleOnSelect}
77+
onClick={this.handleOnClick}
78+
onUpdateHighlighted={this.handleOnUpdateHighlighted} />
6679
</div>
6780

6881
</div>

0 commit comments

Comments
 (0)