Skip to content

Commit f56556f

Browse files
committed
Add click outside toggling to block switcher menu.
Along with #582 this will cover #376. This adds the click outside higher order component to the block switcher menu. So that clicks into block content will close the menu while it is open. **Testing instructions:** Go to a heading or text block. Open the block switcher menu in the top left. Click on that blocks text content outside of the menu. Verify that the menu closes. Repeat this by clicking anywhere and verifying that the switcher closes. Verify that the switcher still works by clicking on it.
1 parent 955656e commit f56556f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

editor/components/block-switcher/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import { connect } from 'react-redux';
55
import { uniq, get, reduce } from 'lodash';
6+
import clickOutside from 'react-click-outside';
67

78
/**
89
* Internal dependencies
@@ -19,6 +20,14 @@ class BlockSwitcher extends wp.element.Component {
1920
};
2021
}
2122

23+
handleClickOutside() {
24+
if ( ! this.state.open ) {
25+
return;
26+
}
27+
28+
this.toggleMenu();
29+
}
30+
2231
toggleMenu() {
2332
this.setState( {
2433
open: ! this.state.open
@@ -94,4 +103,4 @@ export default connect(
94103
} );
95104
}
96105
} )
97-
)( BlockSwitcher );
106+
)( clickOutside( BlockSwitcher ) );

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"lodash": "^4.17.4",
6666
"react": "^15.5.4",
6767
"react-autosize-textarea": "^0.4.2",
68+
"react-click-outside": "^2.3.0",
6869
"react-dom": "^15.5.4",
6970
"react-redux": "^5.0.4",
7071
"react-slot-fill": "^1.0.0-alpha.11",

0 commit comments

Comments
 (0)