Merge pull request #347 from catchonme/master

中文输入未完成时不发送加载选项的请求
This commit is contained in:
liaoxuezhi 2019-11-15 11:09:14 +08:00 committed by GitHub
commit b1ad9218e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 5 deletions

63
src/components/Input.tsx Normal file
View File

@ -0,0 +1,63 @@
import React from 'react';
import {autobind} from '../utils/helper';
export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {
forwardedRef: React.Ref<HTMLInputElement>;
}
export interface InputState {
value: any;
}
class InputInner extends React.Component<InputProps, InputState> {
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<HTMLInputElement>) {
this.isOnComposition = e.type !== 'compositionend';
if (!this.isOnComposition) {
this.handleChange(e as any);
}
}
@autobind
handleChange(e: React.ChangeEvent<HTMLInputElement>) {
const {onChange} = this.props;
const value = e.currentTarget.value;
this.isOnComposition || (onChange && onChange(e));
this.setState({
value
});
}
render() {
const {forwardedRef, ...rest} = this.props;
return (
<input
{...rest}
value={this.state.value}
ref={forwardedRef}
onChange={this.handleChange}
onCompositionStart={this.handleComposition}
onCompositionUpdate={this.handleComposition}
onCompositionEnd={this.handleComposition}
/>
);
}
}
export default React.forwardRef<HTMLInputElement>((props, ref) => {
return <InputInner {...props} forwardedRef={ref} />;
}) as React.ReactType<React.InputHTMLAttributes<HTMLInputElement>>;

View File

@ -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<SelectProps, SelectState> {
})}
>
<Icon icon="search" className="icon" />
<input
<Input
{...getInputProps({
onFocus: this.onFocus,
onBlur: this.onBlur,

View File

@ -153,7 +153,7 @@ export default class ComboControl extends React.Component<ComboProps> {
});
if (store.activeKey >= values.length) {
store.setActiveKey(values.length - 1);
store.setActiveKey(Math.max(0, values.length - 1));
}
}
}

View File

@ -244,7 +244,7 @@ export class FormItemWrap extends React.Component<FormItemProps> {
// 强制不渲染 label 的话
if (renderLabel === false) {
label = false;
label = label === false ? false : '';
}
description = description || desc;

View File

@ -115,7 +115,7 @@ export default class SelectControl extends React.Component<SelectProps, any> {
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);

View File

@ -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<
)
)}
<input
<Input
{...getInputProps({
name,
ref: this.inputRef,