[web] listen to window.onKeyDown
This commit is contained in:
parent
9bfde2a3ae
commit
af2319aa64
|
@ -7,10 +7,6 @@ import FilterDocs from './FilterDocs'
|
|||
|
||||
export default class FilterInput extends Component {
|
||||
|
||||
static contextTypes = {
|
||||
returnFocus: React.PropTypes.func,
|
||||
}
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
|
||||
|
@ -91,7 +87,6 @@ export default class FilterInput extends Component {
|
|||
|
||||
blur() {
|
||||
ReactDOM.findDOMNode(this.refs.input).blur()
|
||||
this.context.returnFocus()
|
||||
}
|
||||
|
||||
select() {
|
||||
|
|
|
@ -69,5 +69,7 @@ export default connect(
|
|||
updateFlow: flowsActions.update,
|
||||
},
|
||||
undefined,
|
||||
{ withRef: true }
|
||||
{
|
||||
withRef: true
|
||||
}
|
||||
)(MainView)
|
||||
|
|
|
@ -4,17 +4,13 @@ import _ from 'lodash'
|
|||
|
||||
import {Key} from '../utils.js'
|
||||
|
||||
Prompt.contextTypes = {
|
||||
returnFocus: PropTypes.func
|
||||
}
|
||||
|
||||
Prompt.propTypes = {
|
||||
options: PropTypes.array.isRequired,
|
||||
done: PropTypes.func.isRequired,
|
||||
prompt: PropTypes.string,
|
||||
}
|
||||
|
||||
export default function Prompt({ prompt, done, options }, context) {
|
||||
export default function Prompt({ prompt, done, options }) {
|
||||
const opts = []
|
||||
|
||||
function keyTaken(k) {
|
||||
|
@ -35,7 +31,7 @@ export default function Prompt({ prompt, done, options }, context) {
|
|||
}
|
||||
opts.push(opt)
|
||||
}
|
||||
|
||||
|
||||
function onKeyDown(event) {
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
|
@ -44,7 +40,6 @@ export default function Prompt({ prompt, done, options }, context) {
|
|||
return
|
||||
}
|
||||
done(key.key || false)
|
||||
context.returnFocus()
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -12,23 +12,18 @@ import { Key } from '../utils.js'
|
|||
|
||||
class ProxyAppMain extends Component {
|
||||
|
||||
static childContextTypes = {
|
||||
returnFocus: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
static contextTypes = {
|
||||
router: PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context)
|
||||
|
||||
this.focus = this.focus.bind(this)
|
||||
this.onKeyDown = this.onKeyDown.bind(this)
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
this.props.appInit()
|
||||
window.addEventListener('keydown', this.props.onKeyDown);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.appDestruct()
|
||||
window.removeEventListener('keydown', this.props.onKeyDown);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
|
@ -42,49 +37,10 @@ class ProxyAppMain extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo listen to window's key events
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.focus()
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.appDestruct()
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo use props
|
||||
*/
|
||||
getChildContext() {
|
||||
return { returnFocus: this.focus }
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo remove it
|
||||
*/
|
||||
focus() {
|
||||
document.activeElement.blur()
|
||||
window.getSelection().removeAllRanges()
|
||||
ReactDOM.findDOMNode(this).focus()
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo move to actions
|
||||
* @todo bind on window
|
||||
*/
|
||||
onKeyDown(e) {
|
||||
if (e.ctrlKey) {
|
||||
return
|
||||
}
|
||||
this.props.onKeyDown(e.keyCode)
|
||||
e.preventDefault()
|
||||
}
|
||||
|
||||
render() {
|
||||
const { showEventLog, location, children, query } = this.props
|
||||
return (
|
||||
<div id="container" tabIndex="0" onKeyDown={this.onKeyDown}>
|
||||
<div id="container" tabIndex="0">
|
||||
<Header ref="header" query={query} />
|
||||
{React.cloneElement(
|
||||
children,
|
||||
|
|
|
@ -4,27 +4,17 @@ import ValidateEditor from './ValueEditor/ValidateEditor'
|
|||
|
||||
export default class ValueEditor extends Component {
|
||||
|
||||
static contextTypes = {
|
||||
returnFocus: PropTypes.func,
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
content: PropTypes.string.isRequired,
|
||||
onDone: PropTypes.func.isRequired,
|
||||
inline: PropTypes.bool,
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.focus = this.focus.bind(this)
|
||||
}
|
||||
|
||||
render() {
|
||||
var tag = this.props.inline ? "span" : 'div'
|
||||
var tag = this.props.inline ? 'span' : 'div'
|
||||
return (
|
||||
<ValidateEditor
|
||||
{...this.props}
|
||||
onStop={() => this.context.returnFocus()}
|
||||
tag={tag}
|
||||
/>
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue