在react-select中访问内部输入元素

问题描述 投票:0回答:1

那里有一个名为farsitype.js的脚本,我想将它与react-select组件一起使用,但是无法直接访问内部输入字段以为其添加属性。有什么方法可以在react-select中向内部输入字段添加属性?

javascript reactjs react-select
1个回答
0
投票

如果您正在谈论此react-select库。您可以像这样自定义Input组件:

import React from 'react';
import Select, { components } from 'react-select';
import { typeOptions } from '../data';

const Input = props => {
  // add attribues to the component below
  return <components.Input {...props} />;
};

export default () => (
  <Select
    components={{ Input }}
    options={typeOptions}
  />
);
© www.soinside.com 2019 - 2024. All rights reserved.