Open
Description
I have a Autocomplete component whoose list an array of MenuItems. When i click in a specific value, only [Object Object] is show.
Here is my code:
class AutoCompleteEspecificacaoItemComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
dataSource: [],
hover: false,
itemHover: '',
};
}
onChangeDataSource = (value, event) => {
const url = this.props.url;
let textoAPesquisar = event;
if (event.length >= this.props.minimunInputLength) {
if (this.props.filtrarSomenteCodigo) {
if (this.props.ehPropostaMaterialServico) {
textoAPesquisar = formatarNumerosComZerosEsquerda(textoAPesquisar, 8);
}
else {
textoAPesquisar = formatarNumerosComZerosEsquerda(textoAPesquisar, 9);
}
}
axios.get(url, {
params: {
textoAPesquisar,
page: 1,
sizePerPage: 15,
filtrarPorMaterial: this.props.filtrarPorMaterial,
filtrarPorServico: this.props.filtrarPorServico,
},
})
.then(({ data: { dados } }) => {
const newArr = [];
//eslint-disable-next-line
dados.map((item) => {
let codigoEspecificacao;
if (this.props.filtrarSomenteCodigo) {
codigoEspecificacao = item.codigo;
}
else if (this.props.ehPropostaMaterialServico) {
codigoEspecificacao = item.nome;
}
else {
codigoEspecificacao = item.especificacao;
}
const obj = {
descricao: codigoEspecificacao,
};
newArr.push(obj);
});
this.setState({ dataSource: newArr });
});
}
};
mouseOver = (event) => {
this.setState({
hover: true,
itemHover: event.target.textContent,
});
};
mouseOut = (event) => {
this.setState({
hover: false,
itemHover: event.target.textContent,
searchText: '',
});
};
filtro = (searchText, key) => {
if (searchText) return key;
return 'Sem resultados';
};
render() {
return (
<div style={{ whiteSpace: 'pre-wrap' }}>
<Rotulo valor={this.props.rotulo} htmlFor={this.props.id} />
{this.props.textoAjuda && <InfoButton info={this.props.textoAjuda} />}
<Field
id={this.props.id}
name={this.props.name}
component={AutoComplete}
hintText={this.props.placeholder}
openOnFocus
onInput={this.props.onInput}
filter={this.filtro}
menuStyle={{ fontSize: '14px',
lineHeight: 'unset',
padding: '7px 0px',
whiteSpace: 'normal',
alignItems: 'center',
display: 'inline-flex',
minHeight: '28px',
width: '100%',
}}
// dataSource={this.state.dataSource.map(item => item.descricao)}
dataSource={this.state.dataSource.map(item => ({
text: item.descricao,
value: (
<MenuItem
primaryText={item.descricao}
style={{ fontSize: '14px',
lineHeight: 'unset',
padding: '7px 0px',
whiteSpace: 'normal',
alignItems: 'center',
display: 'inline-flex',
minHeight: '28px',
width: '100%',
}}
className={this.state.hover && this.state.itemHover === item.descricao
? 'hoverColor' : 'noHoverColor'}
onMouseOver={this.mouseOver}
onMouseOut={this.mouseOut}
/>
),
}))}
onChange={this.onChangeDataSource}
underlineStyle={{ fill: '#000000' }}
style={{ marginTop: '-15px' }}
listStyle={{ maxHeight: 200, overflow: 'auto', whiteSpace: 'wrap' }}
fullWidth
/>
</div>
);
}
}
Someone could help me?
Metadata
Metadata
Assignees
Labels
No labels