From 0dddb878c8631c6de7e56b22ca40b8fedba2edca Mon Sep 17 00:00:00 2001 From: Angel Gomez Salazar Date: Tue, 14 Feb 2017 19:38:47 -0800 Subject: [PATCH 01/11] Change menu and select behavior to what is expected --- css/app.css | 6 --- src/components/GraphiQL.js | 10 ++++ src/components/ToolbarMenu.js | 64 ++++++++++++++++++------ src/components/ToolbarSelect.js | 89 +++++++++++++++++++++------------ 4 files changed, 115 insertions(+), 54 deletions(-) diff --git a/css/app.css b/css/app.css index 8b1382bf4ee..2132d5fcd06 100644 --- a/css/app.css +++ b/css/app.css @@ -331,12 +331,6 @@ left: 0; min-width: 100%; top: -5px; - visibility: hidden; -} - -.graphiql-container .toolbar-menu:active .toolbar-menu-items, -.graphiql-container .toolbar-select:active .toolbar-select-options { - visibility: visible; } .graphiql-container .execute-options > li, diff --git a/src/components/GraphiQL.js b/src/components/GraphiQL.js index 20c834575c9..660bdeea6dd 100644 --- a/src/components/GraphiQL.js +++ b/src/components/GraphiQL.js @@ -227,6 +227,16 @@ export class GraphiQL extends React.Component { title="Prettify Query" label="Prettify" /> + + + + + + + + + + ; const footer = find(children, child => child.type === GraphiQL.Footer); diff --git a/src/components/ToolbarMenu.js b/src/components/ToolbarMenu.js index a25f95e3b69..3086f649411 100644 --- a/src/components/ToolbarMenu.js +++ b/src/components/ToolbarMenu.js @@ -14,22 +14,54 @@ 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, + } + + constructor(props) { + super(props); + this.state = { visibility: 'hidden' }; + } + + render() { + const ulStyle = { + visibility: this.state.visibility + } + return ( + { + document.addEventListener('click', this.handleClick.bind(this), false); + }} + title={this.props.title}> + {this.props.label} + + + + + + ); + } + + handleClick(e) { + if (ReactDOM.findDOMNode(this) !== e.target) { + e.preventDefault(); + this.setState({ visibility: 'hidden' }); + } + } + + handleOpen = e => { + e.preventDefault(); + this.setState({ visibility: 'visible' }); + }; + + } ToolbarMenu.propTypes = { title: PropTypes.string, diff --git a/src/components/ToolbarSelect.js b/src/components/ToolbarSelect.js index 7e935cd0012..8fed68883fd 100644 --- a/src/components/ToolbarSelect.js +++ b/src/components/ToolbarSelect.js @@ -14,42 +14,67 @@ import React, { PropTypes } from 'react'; * * A select-option style button to use within the Toolbar. * - * Note that, like React's