Skip to content

Commit

Permalink
Merge pull request #1633 from HSLdevcom/fix-time-input-update
Browse files Browse the repository at this point in the history
Fix updating time input when changing time
  • Loading branch information
rrudd authored Jun 1, 2017
2 parents 4b4699b + 561e644 commit a304b81
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
21 changes: 19 additions & 2 deletions app/component/ItineraryTimePicker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { PropTypes } from 'react';
import { isMobile } from '../util/browser';

const setSelectionRange = e => e.target.setSelectionRange(0, 2);

export default class ItineraryTimePicker extends React.Component {
static propTypes = {
changeTime: PropTypes.func.isRequired,
Expand All @@ -19,6 +21,21 @@ export default class ItineraryTimePicker extends React.Component {
this.onChangeTime = this.onChangeTime.bind(this);
}

componentWillReceiveProps({ initHours, initMin }) {
if (
Number(this.hourEl.value) !== Number(initHours) ||
Number(this.minEl.value) !== Number(initMin)
) {
this.setState({
hours: initHours,
minutes: initMin,
lastKey: 0,
oldHour: initHours,
oldMinute: initMin,
});
}
}

onChangeTime(event) {
// If backspace is pressed, erase the value
const timePropertyId = event.target.id === 'inputHours' ? 'hours' : 'minutes';
Expand Down Expand Up @@ -191,7 +208,7 @@ export default class ItineraryTimePicker extends React.Component {
className="time-input-field"
value={this.state.hours}
maxLength={3}
onClick={e => e.target.setSelectionRange(0, 2)}
onClick={setSelectionRange}
onChange={this.onChangeTime}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyDown}
Expand All @@ -204,7 +221,7 @@ export default class ItineraryTimePicker extends React.Component {
className="time-input-field"
value={this.state.minutes}
maxLength={3}
onClick={e => e.target.setSelectionRange(0, 2)}
onClick={setSelectionRange}
onChange={this.onChangeTime}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyDown}
Expand Down
35 changes: 20 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,22 @@ [email protected], async@^1.3.0, async@^1.4.0, async@^1.5.0, async@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"

async@2.1.5, async@^2.1.2, async@^2.1.5:
version "2.1.5"
resolved "https://registry.yarnpkg.com/async/-/async-2.1.5.tgz#e587c68580994ac67fc56ff86d3ac56bdbe810bc"
async@2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/async/-/async-2.4.1.tgz#62a56b279c98a11d0987096a01cc3eeb8eb7bbd7"
dependencies:
lodash "^4.14.0"

async@^0.9.0, async@~0.9.0:
version "0.9.2"
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"

async@^2.1.2, async@^2.1.5:
version "2.1.5"
resolved "https://registry.yarnpkg.com/async/-/async-2.1.5.tgz#e587c68580994ac67fc56ff86d3ac56bdbe810bc"
dependencies:
lodash "^4.14.0"

async@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/async/-/async-1.0.0.tgz#f8fc04ca3a13784ade9e1641af98578cfbd647a9"
Expand Down Expand Up @@ -1541,11 +1547,11 @@ camelcase@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-3.0.0.tgz#32fc4b9fcdaf845fcdf7e73bb97cac2261f0ab0a"

[email protected]:
[email protected], caniuse-db@^1.0.30000187, caniuse-db@^1.0.30000624:
version "1.0.30000671"
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000671.tgz#9f071bbc7b96994638ccbaf47829d58a1577a8ed"

caniuse-db@^1.0.30000187, caniuse-db@^1.0.30000624, caniuse-db@^1.0.30000628:
caniuse-db@^1.0.30000628:
version "1.0.30000631"
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000631.tgz#8aa6f65cff452c4aba1c2aaa1e724102fbb9114f"

Expand Down Expand Up @@ -3555,9 +3561,9 @@ gemini-coverage@^1.0.0:
q "^1.4.1"
q-io "^2.0.6"

gemini@4.18.1:
version "4.18.1"
resolved "https://registry.yarnpkg.com/gemini/-/gemini-4.18.1.tgz#0a98cd1ea078daf56aa3c01e50ded7b8ad042777"
gemini@5.0.0-alpha.1:
version "5.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/gemini/-/gemini-5.0.0-alpha.1.tgz#314792fdc08b9b6605bb69e72044445523206df7"
dependencies:
aliasify "^1.7.2"
bluebird "^3.4.6"
Expand All @@ -3572,6 +3578,7 @@ [email protected]:
gemini-configparser "^0.1.1"
gemini-core "^1.0.0"
gemini-coverage "^1.0.0"
graceful-fs "^4.1.11"
handlebars "^4.0.5"
inherit "~2.2.1"
js-yaml "^3.2.5"
Expand Down Expand Up @@ -3784,7 +3791,7 @@ got@^3.2.0:
read-all-stream "^3.0.0"
timed-out "^2.0.0"

graceful-fs@^4.1.10, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
graceful-fs@^4.1.10, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

Expand Down Expand Up @@ -4672,7 +4679,7 @@ json-stable-stringify@~0.0.0:
dependencies:
jsonify "~0.0.0"

[email protected], json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.0, json-stringify-safe@~5.0.1:
[email protected], json-stringify-safe@~5.0.0, json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"

Expand Down Expand Up @@ -7023,11 +7030,9 @@ range-parser@^1.0.3, range-parser@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"

[email protected]:
version "3.12.0"
resolved "https://registry.yarnpkg.com/raven-js/-/raven-js-3.12.0.tgz#74bd45c87a1ad34476e77bd8385549d76766f6e7"
dependencies:
json-stringify-safe "^5.0.1"
[email protected]:
version "3.15.0"
resolved "https://registry.yarnpkg.com/raven-js/-/raven-js-3.15.0.tgz#ebf95466b7d40fbbc3d6a5085af7c1431607926c"

[email protected]:
version "1.1.3"
Expand Down

0 comments on commit a304b81

Please sign in to comment.