In my application, I have a autocomplete list of names that gets populated when the user types in my textbox. This list is populated by an array being returned by an api call and looks like this in the debugger/DOM:
<ul className="suggestions">
<li>John Brown</li>
<li>Mary Waters</li>
...
</ul>
Notice that there are 2 spaces between the first and last name. This might be because the data being returned is "dirty" or perhaps its by design. Lets assume though, that I want to keep those 2 spaces. My problem is that when the user clicks on of the items, it triggers my event handler which looks like this:
onClick = e => {
this.setState({
activeSuggestion: 0,
filteredSuggestions: [],
showSuggestions: false,
userInput: e.currentTarget.innerText
});
};
When I check the value of e.currentTarget.innerText
it now shows "John Brown" with only a single space. I don't have any slice, splice, replace, etc... methods to parse this string to remove it so my question then is "Does .innerText" remove the 2nd space automatically? If so, is there a way to keep the 2nd space when grabbing the userInput selected by the user?"