diff --git a/css/app.css b/css/app.css
index 8b1382bf4ee..89c81ca2199 100644
--- a/css/app.css
+++ b/css/app.css
@@ -327,6 +327,10 @@
visibility: hidden;
}
+.graphiql-container .toolbar-menu-items.open {
+ visibility: visible;
+}
+
.graphiql-container .toolbar-select-options {
left: 0;
min-width: 100%;
@@ -334,8 +338,7 @@
visibility: hidden;
}
-.graphiql-container .toolbar-menu:active .toolbar-menu-items,
-.graphiql-container .toolbar-select:active .toolbar-select-options {
+.graphiql-container .toolbar-select-options.open {
visibility: visible;
}
diff --git a/src/components/ToolbarMenu.js b/src/components/ToolbarMenu.js
index a25f95e3b69..4ea4eef4900 100644
--- a/src/components/ToolbarMenu.js
+++ b/src/components/ToolbarMenu.js
@@ -14,27 +14,69 @@ import React, { PropTypes } from 'react';
*
* A menu style button to use within the Toolbar.
*/
-export function ToolbarMenu({ title, label, children }) {
- return (
-
- {label}
-
-
-
- );
-}
+export class ToolbarMenu extends React.Component {
+ static propTypes = {
+ title: PropTypes.string,
+ label: PropTypes.string,
+ }
-ToolbarMenu.propTypes = {
- title: PropTypes.string,
- label: PropTypes.string,
-};
+ constructor(props) {
+ super(props);
+ this.state = { visible: false };
+ }
+
+ componentWillUnmount() {
+ this._release();
+ }
+
+ render() {
+ const visible = this.state.visible;
+ return (
+ {this._node = node;}}
+ title={this.props.title}>
+ {this.props.label}
+
+
+ {this.props.children}
+
+
+ );
+ }
+
+ _subscribe() {
+ if (!this._listener) {
+ this._listener = this.handleClick.bind(this);
+ document.addEventListener('click', this._listener);
+ }
+ }
+
+ _release() {
+ if (this._listener) {
+ document.removeEventListener('click', this._listener);
+ this._listener = null;
+ }
+ }
+
+ handleClick(e) {
+ if (this._node !== e.target) {
+ preventDefault(e);
+ this.setState({ visible: false });
+ this._release();
+ }
+ }
+
+ handleOpen = e => {
+ preventDefault(e);
+ this.setState({ visible: true });
+ this._subscribe();
+ };
+}
export function ToolbarMenuItem({ onSelect, title, label }) {
return (
diff --git a/src/components/ToolbarSelect.js b/src/components/ToolbarSelect.js
index 7e935cd0012..cc8b7101922 100644
--- a/src/components/ToolbarSelect.js
+++ b/src/components/ToolbarSelect.js
@@ -14,42 +14,88 @@ import React, { PropTypes } from 'react';
*
* A select-option style button to use within the Toolbar.
*
- * Note that, like React's