If an option is first selected and then the drop-down is clicked again but no option is selected then the datalist ends up empty but it does not trigger a change.
To change this I added this line under event handlers:
input.addEventListener('click', listClear);
Then I added this function at the end:
function listClear(e) {
const input = target(e);
let changeEvent = new Event(`change`);
input.dispatchEvent(changeEvent);
input.value = ``;
}
This sets the option to the blank choice and then clears the text from the field. Might not be useful depending on the scenario but for me if I didn't do this the underlying option still contained a choice whilst the datalist selector was empty.