<commit_before>var React = require('react/addons');
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var blacklist = require('blacklist');
var classNames = require('classnames');

var Button = require('./Button');

module.exports = React.createClass({
	displayName: 'Dropdown',
	propTypes: {
		alignRight: React.PropTypes.bool,
		buttonHasDisclosureArrow: React.PropTypes.bool,
		buttonLabel: React.PropTypes.string,
		buttonType: React.PropTypes.string,
		children: React.PropTypes.element,
		className: React.PropTypes.string,
		isOpen: React.PropTypes.bool,
		items: React.PropTypes.array.isRequired,
		onSelect: React.PropTypes.func
	},
	getDefaultProps () {
		return {
			buttonHasDisclosureArrow: true,
			onSelect: function() {}
		};
	},
	getInitialState () {
		return {
			isOpen: this.props.isOpen || false
		};
	},
	openDropdown () {
		this.setState({ isOpen: true });
	},
	closeDropdown () {
		this.setState({ isOpen: false });
	},

	renderChildren () {
		return React.Children.map(this.props.children, (child) => {
			return React.cloneElement(child, {<commit_msg>Dropdown: escape closes menu<commit_after>const React = require('react/addons');
const ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
const blacklist = require('blacklist');
const classNames = require('classnames');
const Button = require('./Button');

const ESC_KEYCODE = 27;

module.exports = React.createClass({
	displayName: 'Dropdown',
	propTypes: {
		alignRight: React.PropTypes.bool,
		buttonHasDisclosureArrow: React.PropTypes.bool,
		buttonLabel: React.PropTypes.string,
		buttonType: React.PropTypes.string,
		children: React.PropTypes.element,
		className: React.PropTypes.string,
		isOpen: React.PropTypes.bool,
		items: React.PropTypes.array.isRequired,
		onSelect: React.PropTypes.func
	},
	getDefaultProps () {
		return {
			buttonHasDisclosureArrow: true,
			onSelect: function() {}
		};
	},
	getInitialState () {
		return {
			isOpen: this.props.isOpen || false
		};
	},
	openDropdown () {
		this.setState({ isOpen: true });
	},
	closeDropdown () {
		this.setState({ isOpen: false });
	},
	componentWillUpdate (nextProps, nextState) {
		if (nextState.isOpen) {
			window.addEventListener('keydown', this.handleKeyDown);
		} else {
			window.removeEventListener('keydown', this.handleKeyDown);
		}
	},
	handleKeyDown (e) {
		console.log(e);
		if (e.keyCode === ESC_KEYCODE) {
			this.closeDropdown();
		}
	},

	renderChildren () {
		return React.Children.map(this.props.children, (child) => {
			return React.cloneElement(child, {
{'fraction_non_alphanumeric': 0.14089481946624804, 'fraction_numerical': 0.0007849293563579278, 'mean_word_length': 4.702460850111857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3681709', 'n_tokens_mistral': 896, 'n_tokens_neox': 834, 'n_words': 149}