title: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
onClick: PropTypes.func,
+ onMouseDown: PropTypes.func,
+ onKeyDown: PropTypes.func,
size: PropTypes.number,
active: PropTypes.bool,
pressed: PropTypes.bool,
}
}
+ handleMouseDown = (e) => {
+ if (!this.props.disabled && this.props.onMouseDown) {
+ this.props.onMouseDown(e);
+ }
+ }
+
+ handleKeyDown = (e) => {
+ if (!this.props.disabled && this.props.onKeyDown) {
+ this.props.onKeyDown(e);
+ }
+ }
+
render () {
const style = {
fontSize: `${this.props.size}px`,
title={title}
className={classes}
onClick={this.handleClick}
+ onMouseDown={this.handleMouseDown}
+ onKeyDown={this.handleKeyDown}
style={style}
tabIndex={tabIndex}
disabled={disabled}
title={title}
className={classes}
onClick={this.handleClick}
+ onMouseDown={this.handleMouseDown}
+ onKeyDown={this.handleKeyDown}
style={style}
tabIndex={tabIndex}
disabled={disabled}
this.props.onChange(element.getAttribute('data-index'));
}
break;
+ case 'Tab':
+ if (e.shiftKey) {
+ element = this.node.childNodes[index - 1] || this.node.lastChild;
+ } else {
+ element = this.node.childNodes[index + 1] || this.node.firstChild;
+ }
+ if (element) {
+ element.focus();
+ this.props.onChange(element.getAttribute('data-index'));
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ break;
case 'Home':
element = this.node.firstChild;
if (element) {
}
} else {
const { top } = target.getBoundingClientRect();
+ if (this.state.open && this.activeElement) {
+ this.activeElement.focus();
+ }
this.setState({ placement: top * 2 < innerHeight ? 'bottom' : 'top' });
this.setState({ open: !this.state.open });
}
}
}
+ handleMouseDown = () => {
+ if (!this.state.open) {
+ this.activeElement = document.activeElement;
+ }
+ }
+
+ handleButtonKeyDown = (e) => {
+ switch(e.key) {
+ case ' ':
+ case 'Enter':
+ this.handleMouseDown();
+ break;
+ }
+ }
+
handleClose = () => {
+ if (this.state.open && this.activeElement) {
+ this.activeElement.focus();
+ }
this.setState({ open: false });
}
active={open}
inverted
onClick={this.handleToggle}
+ onMouseDown={this.handleMouseDown}
+ onKeyDown={this.handleButtonKeyDown}
style={{ height: null, lineHeight: '27px' }}
/>
</div>