添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The value property for a Select component has a type definition of Array<string | number> | string | number . However, if you look at the onChange event event.target.value has a type definition of just string. I'm trying to get a multiselect this working but I found this confusing and suspect it's a bug.

  • This is a v1.x issue
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • Expected Behavior

    I believe the value you get from the onChange event should match the type you can supply in the component props.

    Current Behavior

    I have not fully tested this but at least the type returned is only a string.

    Steps to Reproduce

    Here is code similar to what I'm doing.

    export interface IOption {
        label: string;
        value: string | number;
        fixedValue?: boolean;
        disabled?: boolean;
    interface IComponentProps {
        options: IOption[];
    	values: Array<string | number> | string | number;
    <Select                
    	multiple
    	onChange={this.handleChange}
    	value={this.props.values}
    	{this.props.options.map(this.renderOption)}
    </Select>
    renderOption = (x: IOption, i: number) => {
    	return <MenuItem key={i} value={x.value}>{x.label}</MenuItem>
    handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
    	console.log('onChange', event.target.value);
    

    Context

    Right now creating a multiselect feels like it takes too much legwork and from what I have seen people are using other packages to make it work.

    Your Environment

    Version