javascript - How to allow any value to be entered in input in React-Select - Stack Overflow

I'm using react select to render a select ponent:const options = [...]<Select...options={optio

I'm using react select to render a select ponent:

const options = [...]

<Select
 ...
 options={options}
/>

The problem is that I any value that I type that is not inside options won't get selected (when the select ponent is not focused the value will disappear).

Is there any way to make <Select/> more of a suggestions ponent that provides autoplete for options but also allows any value to be entered?

I'm using react select to render a select ponent:

const options = [...]

<Select
 ...
 options={options}
/>

The problem is that I any value that I type that is not inside options won't get selected (when the select ponent is not focused the value will disappear).

Is there any way to make <Select/> more of a suggestions ponent that provides autoplete for options but also allows any value to be entered?

Share asked Sep 13, 2021 at 9:52 nilnil 5591 gold badge6 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You can use the creatable Component to achieve that:

Example from react-select

import React, { Component } from 'react';

import CreatableSelect from 'react-select/creatable';
import { colourOptions } from '../data';

export default class CreatableSingle extends Component<*, State> {
  handleChange = (newValue: any, actionMeta: any) => {
    console.group('Value Changed');
    console.log(newValue);
    console.log(`action: ${actionMeta.action}`);
    console.groupEnd();
  };
  handleInputChange = (inputValue: any, actionMeta: any) => {
    console.group('Input Changed');
    console.log(inputValue);
    console.log(`action: ${actionMeta.action}`);
    console.groupEnd();
  };
  render() {
    return (
      <CreatableSelect
        isClearable
        onChange={this.handleChange}
        onInputChange={this.handleInputChange}
        options={colourOptions}
      />
    );
  }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744652652a4585993.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>