UNPKG

react-microspreadsheet

Version:

A pluggable spreadsheet component.

46 lines (40 loc) 1.35 kB
// Generated by CoffeeScript 1.8.0 var InputField, React, div, input, mori, _ref; React = require('react'); mori = require('mori'); _ref = React.DOM, div = _ref.div, input = _ref.input; InputField = React.createClass({ componentDidMount: function() { return this.refs.input.getDOMNode().focus(); }, componentDidUpdate: function() { var caret, node; node = this.refs.input.getDOMNode(); caret = this.props.caretPosition === null ? node.value.length : this.props.caretPosition; if (!this.wasEditing) { node.focus(); node.setSelectionRange(caret, caret); return this.wasEditing = true; } else if (node !== document.activeElement) { node.focus(); return node.setSelectionRange(caret, caret); } else if (this.props.caretPosition !== null && this.props.caretPosition !== prevProps.caretPosition) { return node.setSelectionRange(caret, caret); } }, componentWillUnmount: function() { return this.wasEditing = false; }, render: function() { return input({ ref: 'input', className: 'mousetrap', onChange: this.handleChange, onClick: this.handleClickInput, onDoubleClick: this.handleDoubleClickInput, onSelect: this.handleSelectText, value: mori.get(this.props.cell, 'raw') }); } }); module.exports = InputField;