我需要下拉菜单中的搜索框。我已插入搜索框,但无法键入任何内容,因为单击时没有光标出现。不确定是否是因为重叠。我该如何解决这个问题?
我在下拉列表中创建了两个搜索框,一个在下拉列表中,另一个是为了查看搜索的实际工作方式。外面的一个可以让我打字,而另一个则不能。
下面是代码。
import React, { Component } from "react";
import ReactDOM from "react-dom";
import DpDwn from "./dropdown.json";
import "./App.css";
import "./carbon-components-stylesheet.css";
import {
DropdownV2,
Search,
Accordion,
AccordionItem
} from "carbon-components-react";
class App extends Component {
constructor(props) {
super(props);
this.state = {
selectedItem: "Label",
selectedId: 0
};
}
render() {
const onChange = search_item => {
console.log(search_item.target.value);
};
const itemToElement = item => {
return (
<li
style={{ height: 20 }}
value={item.value}
onClick={evt => {
evt.preventDefault();
}}
onKeyPress={evt => evt.preventDefault()}
tabIndex={-1}
id="listUsed"
>
<Search
className="some-class"
name="abc"
defaultValue=""
labelText="Search"
closeButtonLabelText=""
placeHolderText="Search"
onChange={onChange}
onClick={event => {
console.log("hi");
}}
id="search-2"
/>
<Accordion>
{item.lvl_1.map((item0, index) => {
return (
<AccordionItem title={item0.BUSINESS_UNIT_NAME} id="lvl1">
{item0.lvl_2.map((item1, index) => {
return (
<AccordionItem title={item1.BRAND_NAME} id="lvl2">
{item1.lvl_3.map((item2, index) => {
return (
<p
onClick={() => {
ReactDOM.findDOMNode(
this
).getElementsByClassName(
"bx--list-box__menu"
)[0].style.display = "none";
ReactDOM.findDOMNode(
this
).getElementsByClassName(
"bx--list-box__menu-icon bx--list-box__menu-icon--open"
)[0].className = "bx--list-box__menu-icon";
this.setState({
selectedItem: item2.NAME,
selectedId: item2.VALUE
});
}}
>
{item2.NAME}
</p>
);
})}
</AccordionItem>
);
})}
</AccordionItem>
);
})}
</Accordion>
</li>
);
};
const items4dropDown = DpDwn.map(item => ({
lvl_1: item.lvl_1
}));
return (
<div className="App">
<div style={{ width: 300, position: "relative", top: "100px" }}>
<Search
className="some-class"
name="abc"
defaultValue=""
labelText="Search"
closeButtonLabelText=""
placeHolderText="Search"
onChange={onChange}
onClick={event => {
console.log("hi");
}}
id="search-1"
/>
<DropdownV2
label={this.state.selectedItem}
ariaLabel="Dropdown"
items={items4dropDown}
itemToElement={itemToElement}
onClick={evt => {
evt.preventDefault();
}}
/>
</div>
</div>
);
}
}
export default App;
我需要下拉菜单中的搜索框显示光标,以便它允许输入文本