我有一個工作材料-UI自動完成我可以搜索值我可以使用鍵盤上的箭頭鍵選擇項目,我可以用返回鍵選擇項目。如果我用鼠標點擊一個項目,建議就會消失,沒有任何東西被選中。我一直在研究這個問題一段時間,我找不到解決它的人。官方Material-UI網站上的代碼示例具有相同的問題,您無法使用鼠標選擇項目。材料-UI自動完成將不會選擇左鍵點擊
import React from 'react';
import AutoComplete from 'material-ui/lib/auto-complete';
var sampleFacilities = require('../sample-facility');
var NewOutbreakForm = React.createClass({
getInitialState: function() {
return {
facilities: [],
facility: ''
}
},
componentDidMount: function() {
this.setState({ facilities: sampleFacilities, facility: '' });
},
selectedItem: function(chosenRequest, index) {
this.setState({ facility: chosenRequest });
},
render: function() {
return (
<div className="container">
<div className="panel panel-default">
<div className="panel-heading">
<h3 className="panel-title">New Outbreak</h3>
</div>
<div className="panel-body">
<div className="row">
<did className="col-md-6">
<AutoComplete floatingLabelText="Facility Name" onNewRequest={this.selectedItem} searchText={this.state.facility} dataSource={this.state.facilities} filter={AutoComplete.caseInsensitiveFilter} maxSearchResults={5} />
</did>
<did className="col-md-6">
</did>
</div>
</div>
</div>
</div>
);
}
});
export default NewOutbreakForm;