我使用的是ReactJS v18.2和Reaction-SELECT v5.7.
我想向<Select/>
组件的输入元素添加一个自定义属性(例如data-test
),但在文档中找不到类似的内容.
对于我自己的定制功能组件,它只需将其添加到html标记,例如
<input type="text" test={XYZ}/>
对于react Select ,它根本不会显示在DOM中.我怎么才能修好它呢?
我使用的是ReactJS v18.2和Reaction-SELECT v5.7.
我想向<Select/>
组件的输入元素添加一个自定义属性(例如data-test
),但在文档中找不到类似的内容.
对于我自己的定制功能组件,它只需将其添加到html标记,例如
<input type="text" test={XYZ}/>
对于react Select ,它根本不会显示在DOM中.我怎么才能修好它呢?
我面临着同样的问题,并使用了一种变通方法来使其发挥作用.为此,我必须创建自定义输入组件.
import React from 'react'
import Select, { components } from 'react-select'
const CustomInput = (props) => {
return (
<components.Input
{...props}
data-test="abc" // put the value you want..
/>
)
}
const CustomSelect = () => {
return (
<Select
components={{ Input: CustomInput }}
options={[ /* your options here */]}
/>
)
}
export default CustomSelect