@@ -9,38 +9,45 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
99
1010'use strict' ;
1111
12- function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { " default" : obj } ; }
12+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { ' default' : obj } ; }
1313
14- var _react = require ( " react" ) ;
14+ var _react = require ( ' react' ) ;
1515
1616var _react2 = _interopRequireDefault ( _react ) ;
1717
18- var _tetherDrop = require ( " tether-drop" ) ;
18+ var _tetherDrop = require ( ' tether-drop' ) ;
1919
2020var _tetherDrop2 = _interopRequireDefault ( _tetherDrop ) ;
2121
22+ var _utils = require ( './utils' ) ;
23+
2224//import { TransitionSpring, Spring } from 'react-motion';
2325
24- module . exports = _react2 [ " default" ] . createClass ( {
26+ module . exports = _react2 [ ' default' ] . createClass ( {
2527
2628 displayName : 'SLDSPopover' ,
2729
28- mixins : [ require ( "react-onclickoutside" ) ] ,
30+ mixins : [ require ( 'react-onclickoutside' ) ] ,
31+
32+ handleClickOutside : function handleClickOutside ( ) {
33+ this . handleClose ( ) ;
34+ } ,
2935
30- handleClickOutside : function handleClickOutside ( e ) {
36+ handleClose : function handleClose ( ) {
3137 if ( this . props . onClose ) {
3238 this . props . onClose ( ) ;
3339 }
3440 } ,
3541
3642 propTypes : {
37- targetAttachment : _react2 [ " default" ] . PropTypes . string
43+ targetAttachment : _react2 [ ' default' ] . PropTypes . string
3844 } ,
3945
4046 getDefaultProps : function getDefaultProps ( ) {
4147 return {
42- targetAttachment : "bottom left" ,
43- className : "slds-dropdown"
48+ targetAttachment : 'bottom left' ,
49+ className : 'slds-dropdown' ,
50+ closeOnTabKey : false
4451 } ;
4552 } ,
4653
@@ -71,12 +78,21 @@ module.exports = _react2["default"].createClass({
7178 }
7279 } ,
7380
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+
7490 popoverComp : function popoverComp ( ) {
7591 if ( ! this . state . isOpen ) {
76- return _react2 [ " default" ] . createElement ( " span" , null ) ;
92+ return _react2 [ ' default' ] . createElement ( ' span' , null ) ;
7793 }
78- return _react2 [ " default" ] . createElement (
79- " div" ,
94+ return _react2 [ ' default' ] . createElement (
95+ ' div' ,
8096 { className : 'SLDSPopover ' + this . props . className ,
8197 style : {
8298 transform : 'none' ,
@@ -85,7 +101,9 @@ module.exports = _react2["default"].createClass({
85101 marginBottom : '0.35rem' ,
86102 float : 'inherit' ,
87103 position : 'inherit'
88- } } ,
104+ } ,
105+ onKeyDown : this . handleKeyDown
106+ } ,
89107 this . props . children
90108 ) ;
91109 } ,
@@ -112,7 +130,7 @@ module.exports = _react2["default"].createClass({
112130
113131 renderPopover : function renderPopover ( ) {
114132
115- _react2 [ " default" ] . render ( this . popoverComp ( ) , this . popoverElement ) ;
133+ _react2 [ ' default' ] . render ( this . popoverComp ( ) , this . popoverElement ) ;
116134
117135 if ( this . popoverElement && this . popoverElement . parentNode && this . popoverElement . parentNode . parentNode && this . popoverElement . parentNode . parentNode . className && this . popoverElement . parentNode . parentNode . className . indexOf ( 'drop ' ) > - 1 ) {
118136 this . popoverElement . parentNode . parentNode . style . zIndex = 10001 ;
@@ -123,15 +141,15 @@ module.exports = _react2["default"].createClass({
123141 this . drop . position ( ) ;
124142 }
125143 } else if ( window && document ) {
126- this . drop = new _tetherDrop2 [ " default" ] ( this . dropOptions ( ) ) ;
144+ this . drop = new _tetherDrop2 [ ' default' ] ( this . dropOptions ( ) ) ;
127145 this . drop . once ( 'open' , this . handleOpen ) ;
128146 }
129147 } ,
130148
131149 componentWillUnmount : function componentWillUnmount ( ) {
132150
133151 this . drop . destroy ( ) ;
134- _react2 [ " default" ] . unmountComponentAtNode ( this . popoverElement ) ;
152+ _react2 [ ' default' ] . unmountComponentAtNode ( this . popoverElement ) ;
135153 if ( this . popoverElement . parentNode ) {
136154 this . popoverElement . parentNode . removeChild ( this . popoverElement ) ;
137155 }
@@ -141,7 +159,7 @@ module.exports = _react2["default"].createClass({
141159 } ,
142160
143161 render : function render ( ) {
144- return _react2 [ " default" ] . createElement ( " span" , null ) ;
162+ return _react2 [ ' default' ] . createElement ( ' span' , null ) ;
145163 }
146164
147165} ) ;
0 commit comments