From a43c388cd168a60c90ec0b5d971d9f65316b8275 Mon Sep 17 00:00:00 2001 From: Robert Katzki Date: Mon, 18 Jan 2016 09:40:12 +0100 Subject: [PATCH] feat: allow all standard input type attributes closes #80 --- src/Geosuggest.jsx | 12 ++++++++++-- src/input-attributes.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/input-attributes.js diff --git a/src/Geosuggest.jsx b/src/Geosuggest.jsx index f5c29d0c..214ff066 100644 --- a/src/Geosuggest.jsx +++ b/src/Geosuggest.jsx @@ -2,6 +2,7 @@ import React from 'react'; import GeosuggestItem from './GeosuggestItem'; // eslint-disable-line +import inputAttributes from './input-attributes'; const Geosuggest = React.createClass({ /** @@ -349,6 +350,14 @@ const Geosuggest = React.createClass({ * @return {Function} The React element to render */ render: function() { + const attributes = {}; + + inputAttributes.forEach(inputAttribute => { + if (this.props[inputAttribute]) { + attributes[inputAttribute] = this.props[inputAttribute]; + } + }); + return (// eslint-disable-line no-extra-parens
@@ -356,9 +365,8 @@ const Geosuggest = React.createClass({ className={'geosuggest__input ' + this.props.inputClassName} ref="geosuggestInput" type="text" + {...attributes} value={this.state.userInput} - placeholder={this.props.placeholder} - disabled={this.props.disabled} onKeyDown={this.onInputKeyDown} onChange={this.onInputChange} onFocus={this.onFocus} diff --git a/src/input-attributes.js b/src/input-attributes.js new file mode 100644 index 00000000..9f32a998 --- /dev/null +++ b/src/input-attributes.js @@ -0,0 +1,30 @@ +/** + * Attributes allowed on input elements + */ +export default [ + 'autocapitalize', + 'autocomplete', + 'autocorrect', + 'autofocus', + 'autosave', + 'disabled', + 'form', + 'formaction', + 'formenctype', + 'formmethod', + 'formnovalidate', + 'formtarget', + 'height', + 'inputmode', + 'maxlength', + 'maxlength', + 'name', + 'pattern', + 'placeholder', + 'readonly', + 'required', + 'selectionDirection', + 'size', + 'spellcheck', + 'tabindex' +];