Skip to content

Commit 5ea16a0

Browse files
committed
Picklist Base modal works right
1 parent 51cf217 commit 5ea16a0

File tree

5 files changed

+70
-32
lines changed

5 files changed

+70
-32
lines changed

components/SLDSPicklistBase/index.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ module.exports = React.createClass( {
165165
return (
166166
!this.props.disabled && this.state.isOpen?
167167
<div
168-
ref="popover"
169168
className="slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu"
170169
targetElement={this.refs.button}
171170
style={{maxHeight:'20em'}}>
@@ -176,7 +175,11 @@ module.exports = React.createClass( {
176175

177176
getModalPopover() {
178177
return (
179-
!this.props.disabled && this.state.isOpen?<SLDSPopover className='slds-dropdown' targetElement={this.refs.date} onClose={this.handleClose}>
178+
!this.props.disabled && this.state.isOpen?
179+
<SLDSPopover
180+
className='slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu'
181+
targetElement={this.refs.date}
182+
onClose={this.handleCancel}>
180183
{this.getPopoverContent()}
181184
</SLDSPopover>:null
182185
);

components/SLDSPopover.js

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

1010
'use strict';
1111

12-
import React from "react";
13-
import TetherDrop from "tether-drop";
12+
import React from 'react';
13+
import TetherDrop from 'tether-drop';
14+
import {EventUtil,KEYS} from './utils';
1415
//import { TransitionSpring, Spring } from 'react-motion';
1516

1617
module.exports = React.createClass( {
1718

1819
displayName: 'SLDSPopover',
1920

20-
mixins: [ require( "react-onclickoutside" ) ],
21+
mixins: [ require( 'react-onclickoutside' ) ],
2122

22-
handleClickOutside (e) {
23+
handleClickOutside () {
24+
this.handleClose();
25+
},
26+
27+
handleClose () {
2328
if(this.props.onClose){
2429
this.props.onClose();
2530
}
@@ -66,20 +71,29 @@ module.exports = React.createClass( {
6671
}
6772
},
6873

74+
handleKeyDown (event) {
75+
if(event.keyCode === KEYS.TAB){
76+
EventUtil.trap(event);
77+
this.handleClose();
78+
}
79+
},
80+
6981
popoverComp () {
7082
if(!this.state.isOpen){
7183
return <span></span>;
7284
}
7385
return (
7486
<div className={'SLDSPopover '+this.props.className}
75-
style={{
76-
transform:'none',
77-
WebkitTransform:'none',
78-
marginTop:'0.20rem',
79-
marginBottom:'0.35rem',
80-
float:'inherit',
81-
position:'inherit',
82-
}}>
87+
style={{
88+
transform:'none',
89+
WebkitTransform:'none',
90+
marginTop:'0.20rem',
91+
marginBottom:'0.35rem',
92+
float:'inherit',
93+
position:'inherit',
94+
}}
95+
onKeyDown={this.handleKeyDown}
96+
>
8397
{/*
8498
<Spring
8599
defaultValue={{ val:0 }}

components/utils/EventUtil.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1111

1212
'use strict';
1313

14-
module.exports = {
14+
const EventUtil = {
1515

1616
trapEvent(event){
1717
event.preventDefault();
@@ -20,6 +20,12 @@ module.exports = {
2020
event.nativeEvent.preventDefault();
2121
event.nativeEvent.stopPropagation();
2222
}
23+
},
24+
25+
trap(event){
26+
return EventUtil.trapEvent( event );
2327
}
2428

25-
};
29+
};
30+
31+
module.exports = EventUtil;

demo/pages/HomePage.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default class HomePage extends Component {
9696
]}
9797
value='C0'
9898
label="Contacts"
99-
modal={false}
99+
modal={true}
100100
placeholder = "Select a contact" />
101101
</div>
102102

lib/SLDSPicklistBase/index.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module.exports = _react2['default'].createClass({
4141
value: null,
4242
options: [],
4343
initialFocus: false,
44+
modal: false,
4445
onClick: function onClick() {
4546
console.log('onClick should be defined');
4647
},
@@ -152,26 +153,40 @@ module.exports = _react2['default'].createClass({
152153
this.setFocus();
153154
},
154155

155-
getPopover: function getPopover() {
156+
getPopoverContent: function getPopoverContent() {
157+
return _react2['default'].createElement(_list2['default'], {
158+
ref: 'list',
159+
options: this.props.options,
160+
label: this.props.label,
161+
highlightedIndex: this.state.highlightedIndex,
162+
selectedIndex: this.state.selectedIndex,
163+
onSelect: this.handleSelect,
164+
onUpdateHighlighted: this.handleUpdateHighlighted,
165+
onListBlur: this.handleListBlur,
166+
onListItemBlur: this.handleListItemBlur,
167+
onCancel: this.handleCancel,
168+
theme: this.props.theme });
169+
},
170+
171+
getSimplePopover: function getSimplePopover() {
156172
return !this.props.disabled && this.state.isOpen ? _react2['default'].createElement(
157173
'div',
158174
{
159-
ref: 'popover',
160175
className: 'slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu',
161176
targetElement: this.refs.button,
162177
style: { maxHeight: '20em' } },
163-
_react2['default'].createElement(_list2['default'], {
164-
ref: 'list',
165-
options: this.props.options,
166-
label: this.props.label,
167-
highlightedIndex: this.state.highlightedIndex,
168-
selectedIndex: this.state.selectedIndex,
169-
onSelect: this.handleSelect,
170-
onUpdateHighlighted: this.handleUpdateHighlighted,
171-
onListBlur: this.handleListBlur,
172-
onListItemBlur: this.handleListItemBlur,
173-
onCancel: this.handleCancel,
174-
theme: this.props.theme })
178+
this.getPopoverContent()
179+
) : null;
180+
},
181+
182+
getModalPopover: function getModalPopover() {
183+
return !this.props.disabled && this.state.isOpen ? _react2['default'].createElement(
184+
_SLDSPopover2['default'],
185+
{
186+
className: 'slds-dropdown slds-dropdown--left slds-dropdown--small slds-dropdown--menu',
187+
targetElement: this.refs.date,
188+
onClose: this.handleClose },
189+
this.getPopoverContent()
175190
) : null;
176191
},
177192

@@ -217,7 +232,7 @@ module.exports = _react2['default'].createClass({
217232
),
218233
_react2['default'].createElement(_SLDSIcons2.Icon, { name: 'down', category: 'utility' })
219234
),
220-
this.getPopover()
235+
this.props.modal ? this.getModalPopover() : this.getSimplePopover()
221236
)
222237
)
223238
);

0 commit comments

Comments
 (0)