]> git.wincent.com - hextrapolate.git/commitdiff
Allow user to fully clear input field
authorGreg Hurrell <greg@hurrell.net>
Sat, 1 Aug 2015 03:00:15 +0000 (20:00 -0700)
committerGreg Hurrell <greg@hurrell.net>
Sat, 1 Aug 2015 03:00:15 +0000 (20:00 -0700)
src/App.js
src/Field.react.js

index 41aedb5eef156bddced99e76b1f09b39195273f9..87ca53fc3b4cc2421a447dd151400c7a9c3695b6 100644 (file)
@@ -14,7 +14,7 @@ export default class App extends React.Component {
   constructor(props) {
     super(props);
     this.state = {
-      value: '0',
+      value: null,
     };
   }
 
index 6bc42c27b8104030fb779643f304038f4fd55ba1..4dab605085aa8ef4b348bebf245bc1c7525b94c9 100644 (file)
@@ -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;
   }