From 02cf4f59538daafb2f6b66fa5af331a2bcadecaf Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 29 Nov 2017 10:36:27 +0100 Subject: [PATCH] Change input types to be hidden via CSS so autoComplete can be used --- examples/src/app.js | 2 + examples/src/components/AutoComplete.js | 78 +++++++++++++++++++++++++ less/control.less | 13 +++++ scss/control.scss | 12 +++- src/Select.js | 39 +++++++++++-- 5 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 examples/src/components/AutoComplete.js diff --git a/examples/src/app.js b/examples/src/app.js index ba23d8954b..26c14fa42f 100644 --- a/examples/src/app.js +++ b/examples/src/app.js @@ -15,10 +15,12 @@ import NumericSelect from './components/NumericSelect'; import BooleanSelect from './components/BooleanSelect'; import Virtualized from './components/Virtualized'; import States from './components/States'; +import AutoComplete from './components/AutoComplete'; ReactDOM.render(
+ diff --git a/examples/src/components/AutoComplete.js b/examples/src/components/AutoComplete.js new file mode 100644 index 0000000000..49435b800d --- /dev/null +++ b/examples/src/components/AutoComplete.js @@ -0,0 +1,78 @@ +import React from 'react'; +import createClass from 'create-react-class'; +import PropTypes from 'prop-types'; +import Select from 'react-select'; + +const STATES = require('../data/states'); + +var AutoCompleteField = createClass({ + displayName: 'AutoCompleteField', + propTypes: { + label: PropTypes.string, + searchable: PropTypes.bool, + }, + componentDidMount() { + // reveal hidden input for testing + document.querySelector('[autocomplete="country"]').classList.remove('Select-hidden'); + }, + getDefaultProps () { + return { + label: 'States:', + searchable: true, + }; + }, + getInitialState () { + return { + selectValue: '', + clearable: true, + rtl: false, + }; + }, + switchCountry (e) { + var newCountry = e.target.value; + this.setState({ + country: newCountry, + selectValue: null, + }); + }, + updateValue (newValue) { + this.setState({ + selectValue: newValue, + }); + }, + toggleCheckbox (e) { + let newState = {}; + newState[e.target.name] = e.target.checked; + this.setState(newState); + }, + render () { + var options = [ + { value: 'EN', label: 'England' }, + { value: 'DE', label: 'Germany' }, + ]; + return ( +
+

{this.props.label} (Source)

+
+ +
+ this.value = ref} + autoComplete={this.props.autoComplete} name={this.props.name} value={value} disabled={this.props.disabled} /> @@ -956,8 +983,10 @@ class Select extends React.Component { } return valueArray.map((item, index) => ( @@ -1024,6 +1053,7 @@ class Select extends React.Component { let className = classNames('Select', this.props.className, { 'Select--multi': this.props.multi, 'Select--single': !this.props.multi, + 'is-autofilled': this.state.isAutoFilled, 'is-clearable': this.props.clearable, 'is-disabled': this.props.disabled, 'is-focused': this.state.isFocused, @@ -1084,6 +1114,7 @@ Select.propTypes = { 'aria-labelledby': PropTypes.string, // HTML ID of an element that should be used as the label (for assistive tech) arrowRenderer: PropTypes.func, // Create drop-down caret element autoBlur: PropTypes.bool, // automatically blur the component when an option is selected + autoComplete: PropTypes.string, // support for form auto completion autoFocus: PropTypes.bool, // autofocus the component on mount autofocus: PropTypes.bool, // deprecated; use autoFocus instead autosize: PropTypes.bool, // whether to enable autosizing or not