@@ -9,38 +9,45 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
9
9
10
10
'use strict' ;
11
11
12
- function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { " default" : obj } ; }
12
+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { ' default' : obj } ; }
13
13
14
- var _react = require ( " react" ) ;
14
+ var _react = require ( ' react' ) ;
15
15
16
16
var _react2 = _interopRequireDefault ( _react ) ;
17
17
18
- var _tetherDrop = require ( " tether-drop" ) ;
18
+ var _tetherDrop = require ( ' tether-drop' ) ;
19
19
20
20
var _tetherDrop2 = _interopRequireDefault ( _tetherDrop ) ;
21
21
22
+ var _utils = require ( './utils' ) ;
23
+
22
24
//import { TransitionSpring, Spring } from 'react-motion';
23
25
24
- module . exports = _react2 [ " default" ] . createClass ( {
26
+ module . exports = _react2 [ ' default' ] . createClass ( {
25
27
26
28
displayName : 'SLDSPopover' ,
27
29
28
- mixins : [ require ( "react-onclickoutside" ) ] ,
30
+ mixins : [ require ( 'react-onclickoutside' ) ] ,
31
+
32
+ handleClickOutside : function handleClickOutside ( ) {
33
+ this . handleClose ( ) ;
34
+ } ,
29
35
30
- handleClickOutside : function handleClickOutside ( e ) {
36
+ handleClose : function handleClose ( ) {
31
37
if ( this . props . onClose ) {
32
38
this . props . onClose ( ) ;
33
39
}
34
40
} ,
35
41
36
42
propTypes : {
37
- targetAttachment : _react2 [ " default" ] . PropTypes . string
43
+ targetAttachment : _react2 [ ' default' ] . PropTypes . string
38
44
} ,
39
45
40
46
getDefaultProps : function getDefaultProps ( ) {
41
47
return {
42
- targetAttachment : "bottom left" ,
43
- className : "slds-dropdown"
48
+ targetAttachment : 'bottom left' ,
49
+ className : 'slds-dropdown' ,
50
+ closeOnTabKey : false
44
51
} ;
45
52
} ,
46
53
@@ -71,12 +78,21 @@ module.exports = _react2["default"].createClass({
71
78
}
72
79
} ,
73
80
81
+ handleKeyDown : function handleKeyDown ( event ) {
82
+ if ( event . keyCode === _utils . KEYS . TAB ) {
83
+ if ( this . props . closeOnTabKey ) {
84
+ _utils . EventUtil . trap ( event ) ;
85
+ this . handleClose ( ) ;
86
+ }
87
+ }
88
+ } ,
89
+
74
90
popoverComp : function popoverComp ( ) {
75
91
if ( ! this . state . isOpen ) {
76
- return _react2 [ " default" ] . createElement ( " span" , null ) ;
92
+ return _react2 [ ' default' ] . createElement ( ' span' , null ) ;
77
93
}
78
- return _react2 [ " default" ] . createElement (
79
- " div" ,
94
+ return _react2 [ ' default' ] . createElement (
95
+ ' div' ,
80
96
{ className : 'SLDSPopover ' + this . props . className ,
81
97
style : {
82
98
transform : 'none' ,
@@ -85,7 +101,9 @@ module.exports = _react2["default"].createClass({
85
101
marginBottom : '0.35rem' ,
86
102
float : 'inherit' ,
87
103
position : 'inherit'
88
- } } ,
104
+ } ,
105
+ onKeyDown : this . handleKeyDown
106
+ } ,
89
107
this . props . children
90
108
) ;
91
109
} ,
@@ -112,7 +130,7 @@ module.exports = _react2["default"].createClass({
112
130
113
131
renderPopover : function renderPopover ( ) {
114
132
115
- _react2 [ " default" ] . render ( this . popoverComp ( ) , this . popoverElement ) ;
133
+ _react2 [ ' default' ] . render ( this . popoverComp ( ) , this . popoverElement ) ;
116
134
117
135
if ( this . popoverElement && this . popoverElement . parentNode && this . popoverElement . parentNode . parentNode && this . popoverElement . parentNode . parentNode . className && this . popoverElement . parentNode . parentNode . className . indexOf ( 'drop ' ) > - 1 ) {
118
136
this . popoverElement . parentNode . parentNode . style . zIndex = 10001 ;
@@ -123,15 +141,15 @@ module.exports = _react2["default"].createClass({
123
141
this . drop . position ( ) ;
124
142
}
125
143
} else if ( window && document ) {
126
- this . drop = new _tetherDrop2 [ " default" ] ( this . dropOptions ( ) ) ;
144
+ this . drop = new _tetherDrop2 [ ' default' ] ( this . dropOptions ( ) ) ;
127
145
this . drop . once ( 'open' , this . handleOpen ) ;
128
146
}
129
147
} ,
130
148
131
149
componentWillUnmount : function componentWillUnmount ( ) {
132
150
133
151
this . drop . destroy ( ) ;
134
- _react2 [ " default" ] . unmountComponentAtNode ( this . popoverElement ) ;
152
+ _react2 [ ' default' ] . unmountComponentAtNode ( this . popoverElement ) ;
135
153
if ( this . popoverElement . parentNode ) {
136
154
this . popoverElement . parentNode . removeChild ( this . popoverElement ) ;
137
155
}
@@ -141,7 +159,7 @@ module.exports = _react2["default"].createClass({
141
159
} ,
142
160
143
161
render : function render ( ) {
144
- return _react2 [ " default" ] . createElement ( " span" , null ) ;
162
+ return _react2 [ ' default' ] . createElement ( ' span' , null ) ;
145
163
}
146
164
147
165
} ) ;
0 commit comments