Awesome. Thanks guys. I’ve updated my page with the first solution:
But I can’t figure out why changing the select list multiple times seems to have a one event lag. It’s always returning the previous value. Bizarre. What am I doing wrong?
viewof countryIndex = {
// Copy country data
var countries = data.slice(0);
// Make an alphabetical version
countries.sort(function(a, b) {
var textA = a.Country.toUpperCase();
var textB = b.Country.toUpperCase();
return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;
});
const div = html`
<select>${countries.map((country, index) => `
<option value="${country.Rank}">${country.Country}</option>`)}
</select><br/>
<input type=range min=1 max=${data.length} style="width:100%; max-width:640px;"/>
`;
const range = div.querySelector("[type=range]");
const select = div.querySelector("select");
div.value = range.value = select.value = defaultCountryIndex;
range.addEventListener("input", () => select.value = div.value = range.valueAsNumber);
select.addEventListener("change", () => range.value = div.value = parseInt(select.value));
return div;
}
It’s because only input events trigger the view to update, and SELECT elements (for whatever reason) use change events rather than input events. So you need to modify your change event listener to dispatch an input event, like so:
Somewhat related, I made an input that could be used with viewOf for the specific case of a slider, a text box, and a few quick access buttons. It is here: