From: Greg Hurrell Date: Sat, 1 Aug 2015 03:00:15 +0000 (-0700) Subject: Allow user to fully clear input field X-Git-Url: https://git.wincent.com/hextrapolate.git/commitdiff_plain/fe623a29dbb8b2b8429fccd102301745f973f40a Allow user to fully clear input field --- diff --git a/src/App.js b/src/App.js index 41aedb5..87ca53f 100644 --- a/src/App.js +++ b/src/App.js @@ -14,7 +14,7 @@ export default class App extends React.Component { constructor(props) { super(props); this.state = { - value: '0', + value: null, }; } diff --git a/src/Field.react.js b/src/Field.react.js index 6bc42c2..4dab605 100644 --- a/src/Field.react.js +++ b/src/Field.react.js @@ -16,6 +16,9 @@ const DIGITS = '0123456789abcdef'; * Convert from canonical (hexadecimal) value to `base`. */ function fromValue(value: string, base: number): string { + if (value === null) { + return ''; + } if (base === 16) { return value; } @@ -25,7 +28,10 @@ function fromValue(value: string, base: number): string { /** * Convert from `base` value to canonical (hexadecimal) value. */ -function toValue(value: string, base: number): string { +function toValue(value: string, base: number): ?string { + if (value === '') { + return null; + } if (base === 16) { return value; }