Interactive interface for browsing global, full-resolution satellite imagery
fix input 1 char restriction and handle focus and blur
Edward Plato7f83c95ceccd
diff --git a/web/js/components/timeline/interval-selector/interval-input.js b/web/js/components/timeline/interval-selector/interval-input.jsindex 38aa517eb..3abbb9863 100644--- a/web/js/components/timeline/interval-selector/interval-input.js+++ b/web/js/components/timeline/interval-selector/interval-input.js@@ -10,34 +10,69 @@ import PropTypes from 'prop-types';const regex = /^[0-9\b]+$/;class IntervalInput extends PureComponent {+ constructor(props) {+ super(props);+ this.state = {+ value: '',+ valid: true+ };+ }onKeyInput = (e) => {let value = e.target.value;if (value === '' || regex.test(value)) {value = Number(value);if (value <= 1000) {- this.props.changeInterval(value);+ this.setValue(value);}}}handleKeyPress = (e) => {- let value = e.target.value;+ let value = this.state.value;if (value === '' || regex.test(value)) {value = Number(value);if (e.key === 'ArrowUp') {if (value < 1000) {- this.props.changeInterval(value + 1);+ this.setValue(value + 1);}} else if (e.key === 'ArrowDown') {if (value > 1) {- this.props.changeInterval(value - 1);+ this.setValue(value - 1);}+ } else if (e.key === 'Enter') {+ this.handleBlur();}}}+ handleFocus = (e) => {+ e.target.select();+ }+ handleBlur = () => {+ let { value } = this.state;+ if (value >= 1 && value < 1000) {+ this.setState({+ valid: true+ }, this.props.changeInterval(value));+ } else {+ this.setState({+ valid: false+ });+ }+ }+ setValue = (value) => {+ this.setState({+ value: value+ });+ }+ componentDidMount() {+ this.setValue(this.props.intervalValue);+ }render() {return (<input className="interval-input" type="text"- min="1" step="1" value={this.props.intervalValue}+ style={this.state.valid ? {} : { borderColor: '#ff0000' }}+ min="1" step="1" value={this.state.value}+ onFocus={this.handleFocus}+ onBlur={this.handleBlur}onKeyDown={this.handleKeyPress}onChange={this.onKeyInput} />);diff --git a/web/js/components/timeline/interval-selector/interval-selector.js b/web/js/components/timeline/interval-selector/interval-selector.jsindex 7168af3d1..d187ad2bb 100644--- a/web/js/components/timeline/interval-selector/interval-selector.js+++ b/web/js/components/timeline/interval-selector/interval-selector.js@@ -13,7 +13,7 @@ import { timeScaleFromNumberKey, timeScaleToNumberKey } from '../../../modules/d*/class CustomIntervalSelectorWidget extends PureComponent {changeInterval = (value) => {- if (value > 0 && value <= 1000) {+ if (value >= 0 && value <= 1000) {this.props.changeCustomInterval(value, this.props.customIntervalZoomLevel);}}@@ -23,15 +23,6 @@ class CustomIntervalSelectorWidget extends PureComponent {}handleKeyPress = (e) => {- // const value = this.state.intervalValue;- // const value = this.props.customDelta;- // if (e.key === 'Enter') {- // if (value > 0) {- // this.changeCustomInterval();- // }- // } else if (e.key === 'Escape') {- // this.props.toggleCustomIntervalModal();- // }if (e.key === 'Escape') {this.props.toggleCustomIntervalModal();}