@@ -14,7 +14,7 @@ class Dropdown extends Component {
1414
1515 this . toggle = this . toggle . bind ( this ) ;
1616 this . close = this . close . bind ( this ) ;
17- this . closeIfClickOutside = this . closeIfClickOutside . bind ( this ) ;
17+ this . closeIfFocusOutside = this . closeIfFocusOutside . bind ( this ) ;
1818
1919 this . containerRef = createRef ( ) ;
2020
@@ -46,15 +46,13 @@ class Dropdown extends Component {
4646 }
4747
4848 /**
49- * Closes the dropdown if a click occurs outside the dropdown wrapper. This
50- * is intentionally distinct from `onClose` in that a click outside the
51- * popover may occur in the toggling of the dropdown via its toggle button.
52- * The correct behavior is to keep the dropdown closed.
53- *
54- * @param {MouseEvent } event Click event triggering `onClickOutside`.
49+ * Closes the dropdown if a focus leaves the dropdown wrapper. This is
50+ * intentionally distinct from `onClose` since focus loss from the popover
51+ * is expected to occur when using the Dropdown's toggle button, in which
52+ * case the correct behavior is to keep the dropdown closed.
5553 */
56- closeIfClickOutside ( event ) {
57- if ( ! this . containerRef . current . contains ( event . target ) ) {
54+ closeIfFocusOutside ( ) {
55+ if ( ! this . containerRef . current . contains ( document . activeElement ) ) {
5856 this . close ( ) ;
5957 }
6058 }
@@ -86,7 +84,7 @@ class Dropdown extends Component {
8684 className = { contentClassName }
8785 position = { position }
8886 onClose = { this . close }
89- onClickOutside = { this . closeIfClickOutside }
87+ onFocusOutside = { this . closeIfFocusOutside }
9088 expandOnMobile = { expandOnMobile }
9189 headerTitle = { headerTitle }
9290 focusOnMount = { focusOnMount }
0 commit comments