From fe623a29dbb8b2b8429fccd102301745f973f40a Mon Sep 17 00:00:00 2001 From: Greg Hurrell Date: Fri, 31 Jul 2015 20:00:15 -0700 Subject: [PATCH] Allow user to fully clear input field --- src/App.js | 2 +- src/Field.react.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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; } -- 2.37.1