From f6f3b22a4840956e49bed897f251be2c31a012e4 Mon Sep 17 00:00:00 2001 From: hedgecox Date: Thu, 30 Jan 2020 17:35:17 +0000 Subject: [PATCH 1/5] Investigation --- src/CustomInput.js | 171 +++++++++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 76 deletions(-) diff --git a/src/CustomInput.js b/src/CustomInput.js index 705b78901..551bd1375 100644 --- a/src/CustomInput.js +++ b/src/CustomInput.js @@ -1,93 +1,112 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classNames from 'classnames'; -import { mapToCssModules } from './utils'; -import CustomFileInput from './CustomFileInput'; +import React from "react"; +import PropTypes from "prop-types"; +import classNames from "classnames"; +import { mapToCssModules } from "./utils"; +import CustomFileInput from "./CustomFileInput"; const propTypes = { - className: PropTypes.string, - id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, - type: PropTypes.string.isRequired, - label: PropTypes.node, - inline: PropTypes.bool, - valid: PropTypes.bool, - invalid: PropTypes.bool, - bsSize: PropTypes.string, - htmlFor: PropTypes.string, - cssModule: PropTypes.object, - children: PropTypes.oneOfType([PropTypes.node, PropTypes.array, PropTypes.func]), - innerRef: PropTypes.oneOfType([ - PropTypes.object, - PropTypes.string, - PropTypes.func, - ]) + className: PropTypes.string, + id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, + type: PropTypes.string.isRequired, + label: PropTypes.node, + inline: PropTypes.bool, + valid: PropTypes.bool, + invalid: PropTypes.bool, + bsSize: PropTypes.string, + htmlFor: PropTypes.string, + cssModule: PropTypes.object, + children: PropTypes.oneOfType([PropTypes.node, PropTypes.array, PropTypes.func]), + innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.func]) }; function CustomInput(props) { - const { - className, - label, - inline, - valid, - invalid, - cssModule, - children, - bsSize, - innerRef, - htmlFor, - ...attributes - } = props; + const { + className, + label, + inline, + valid, + invalid, + cssModule, + children, + bsSize, + innerRef, + htmlFor, + hidden, + ...attributes + } = props; - const type = attributes.type; + console.log(hidden); - const customClass = mapToCssModules(classNames( - className, - `custom-${type}`, - bsSize ? `custom-${type}-${bsSize}` : false, - ), cssModule); + const type = attributes.type; - const validationClassNames = mapToCssModules(classNames( - invalid && 'is-invalid', - valid && 'is-valid', - ), cssModule); + const customClass = mapToCssModules( + classNames(className, `custom-${type}`, bsSize ? `custom-${type}-${bsSize}` : false), + cssModule + ); - const labelHtmlFor = htmlFor || attributes.id; + const validationClassNames = mapToCssModules( + classNames(invalid && "is-invalid", valid && "is-valid"), + cssModule + ); - if (type === 'select') { - const { type, ...rest } = attributes; - return ; - } + const labelHtmlFor = htmlFor || attributes.id; - if (type === 'file') { - return ( - - ); - } + if (type === "select") { + const { type, ...rest } = attributes; + return ( + + ); + } - if (type !== 'checkbox' && type !== 'radio' && type !== 'switch') { - return ; - } + if (type === "file") { + return ; + } - const wrapperClasses = classNames( - customClass, - mapToCssModules(classNames( - 'custom-control', - { 'custom-control-inline': inline } - ), cssModule) - ); + if (type !== "checkbox" && type !== "radio" && type !== "switch") { + return ( + + ); + } - return ( -
- - - {children} -
- ); + const wrapperClasses = classNames( + customClass, + mapToCssModules( + classNames("custom-control", { "custom-control-inline": inline }), + cssModule + ) + ); + + return ( +
+ + + {children} +
+ ); } CustomInput.propTypes = propTypes; From 8e56e4cc6258c78321fddc73577fa88b2935fecc Mon Sep 17 00:00:00 2001 From: Luke Hedgecox Date: Thu, 30 Jan 2020 19:00:10 +0000 Subject: [PATCH 2/5] Fix for custom input hidden attr --- src/CustomInput.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/CustomInput.js b/src/CustomInput.js index 551bd1375..dec86a5ab 100644 --- a/src/CustomInput.js +++ b/src/CustomInput.js @@ -31,12 +31,9 @@ function CustomInput(props) { bsSize, innerRef, htmlFor, - hidden, ...attributes } = props; - console.log(hidden); - const type = attributes.type; const customClass = mapToCssModules( @@ -86,11 +83,11 @@ function CustomInput(props) { ) ); + const { hidden, ...rest } = attributes; return ( -
+