diff --git a/src/components/Input.tsx b/src/components/Input.tsx new file mode 100644 index 00000000..ac3891fe --- /dev/null +++ b/src/components/Input.tsx @@ -0,0 +1,63 @@ +import React from 'react'; +import {autobind} from '../utils/helper'; + +export interface InputProps + extends React.InputHTMLAttributes { + forwardedRef: React.Ref; +} + +export interface InputState { + value: any; +} + +class InputInner extends React.Component { + isOnComposition: boolean = false; + state = {value: this.props.value}; + + componentWillReceiveProps(nextProps: InputProps) { + if (this.props.value !== nextProps.value) { + this.setState({ + value: nextProps.value + }); + } + } + + @autobind + handleComposition(e: React.CompositionEvent) { + this.isOnComposition = e.type !== 'compositionend'; + if (!this.isOnComposition) { + this.handleChange(e as any); + } + } + + @autobind + handleChange(e: React.ChangeEvent) { + const {onChange} = this.props; + const value = e.currentTarget.value; + + this.isOnComposition || (onChange && onChange(e)); + this.setState({ + value + }); + } + + render() { + const {forwardedRef, ...rest} = this.props; + + return ( + + ); + } +} + +export default React.forwardRef((props, ref) => { + return ; +}) as React.ReactType>; \ No newline at end of file diff --git a/src/components/Select.tsx b/src/components/Select.tsx index 8a3fe0c8..b1b8e493 100644 --- a/src/components/Select.tsx +++ b/src/components/Select.tsx @@ -22,6 +22,7 @@ import {highlight} from '../renderers/Form/Options'; import {findDOMNode} from 'react-dom'; import {ClassNamesFn, themeable} from '../theme'; import Checkbox from './Checkbox'; +import Input from './Input'; export interface Option { label?: string; @@ -596,7 +597,7 @@ export class Select extends React.Component { })} > - { }); if (store.activeKey >= values.length) { - store.setActiveKey(values.length - 1); + store.setActiveKey(Math.max(0, values.length - 1)); } } } diff --git a/src/renderers/Form/Item.tsx b/src/renderers/Form/Item.tsx index 4f956394..2939b601 100644 --- a/src/renderers/Form/Item.tsx +++ b/src/renderers/Form/Item.tsx @@ -244,7 +244,7 @@ export class FormItemWrap extends React.Component { // 强制不渲染 label 的话 if (renderLabel === false) { - label = false; + label = label === false ? false : ''; } description = description || desc; diff --git a/src/renderers/Form/Select.tsx b/src/renderers/Form/Select.tsx index 85c5e144..fcb808b0 100644 --- a/src/renderers/Form/Select.tsx +++ b/src/renderers/Form/Select.tsx @@ -115,7 +115,7 @@ export default class SelectControl extends React.Component { throw new Error('fetcher is required'); } - if (this.cache[input] || ~input.indexOf("'") /*中文没输完 233*/) { + if (this.cache[input]) { let options = this.cache[input] || []; let combinedOptions = this.mergeOptions(options); setOptions(combinedOptions); diff --git a/src/renderers/Form/Text.tsx b/src/renderers/Form/Text.tsx index aef0e087..2f0c4c8c 100644 --- a/src/renderers/Form/Text.tsx +++ b/src/renderers/Form/Text.tsx @@ -9,6 +9,7 @@ import debouce = require('lodash/debounce'); import {filter} from '../../utils/tpl'; import find = require('lodash/find'); import {Icon} from '../../components/icons'; +import Input from '../../components/Input'; import {autobind, createObject, setVariable} from '../../utils/helper'; import {isEffectiveApi} from '../../utils/api'; @@ -495,7 +496,7 @@ export default class TextControl extends React.PureComponent< ) )} -