From 32542c668d5045934f35385532c767a8c662e6f5 Mon Sep 17 00:00:00 2001 From: Maxime Cloutier Date: Wed, 15 Jul 2020 10:32:48 -0700 Subject: [PATCH 1/2] Fix react default value --- src/react.tagify.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/react.tagify.js b/src/react.tagify.js index 281a04ae..ff7ea631 100644 --- a/src/react.tagify.js +++ b/src/react.tagify.js @@ -20,7 +20,7 @@ function templatesToString(templates) { const TagifyWrapper = ({ name, - value = "", + value, loading = false, onChange = _ => _, readOnly, @@ -42,17 +42,28 @@ const TagifyWrapper = ({ inputElmRef.current = elm } + let initialValue = defaultValue === undefined ? '' : undefined + let initialDefaultValue + + if (value !== undefined) { + initialValue = typeof value === "string" ? value : JSON.stringify(value) + } + + if (defaultValue !== undefined) { + initialDefaultValue = typeof defaultValue === "string" ? defaultValue : JSON.stringify(defaultValue) + } + const inputAttrs = useMemo( () => ({ ref: handleRef, name, - value: typeof value === "string" ? value : JSON.stringify(value), + value: initialValue, className, readOnly, onChange, autoFocus, placeholder, - defaultValue + defaultValue: initialDefaultValue }), [ defaultValue, From 040ea756e89d2e8986d78ff9148094531a89c7b1 Mon Sep 17 00:00:00 2001 From: Maxime Cloutier Date: Wed, 15 Jul 2020 10:50:59 -0700 Subject: [PATCH 2/2] Update compiled version --- dist/react.tagify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/react.tagify.js b/dist/react.tagify.js index 3af69e03..b22e9fad 100644 --- a/dist/react.tagify.js +++ b/dist/react.tagify.js @@ -1 +1 @@ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.React.tagify=t()}(this,function(){"use strict";function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var e,T=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!==i(e)&&"function"!=typeof e)return{default:e};var t=a();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var u=n?Object.getOwnPropertyDescriptor(e,o):null;u&&(u.get||u.set)?Object.defineProperty(r,o,u):r[o]=e[o]}r.default=e,t&&t.set(e,r);return r}(require("react")),F=require("react-dom/server"),t=require("prop-types"),N=(e=require("./tagify.min.js"))&&e.__esModule?e:{default:e};function a(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return a=function(){return e},e}function P(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);te.length)&&(t=e.length);for(var r=0,n=new Array(t);r