I am working on a lwc containing a dual listbox filled with queried contact values that I need. I am successful at retrieving all contact values.
The end user would like the first option of the contacts list automatically highlighted on component opening so that they only have to click on the arrow to select the value and move it to the right list. However I cannot figure out how to highlight that value. I have tried to trigger it from a button to debug the issue but I do not even know if I am doing it the right way. Here is the code I have written :
HTML
<template iterator:listpa={personAccounts}>
<template if:false={isFromOpp}>
<template if:false={isNoPersonAccountSelectable}>
<lightning-layout-item key={listpa.value.practiceName}>
<lightning-dual-listbox name="eventCtcIds"
label="Person Account (People you will meet)"
options={availableContacts} onchange={handleChange} size="3"
value={listpa.value.eventCtcIds}
required>
</lightning-dual-listbox>
<lightning-button
label="do select" variant="brand"
onclick={handleClick}></lightning-button>
</lightning-layout-item>
</template>
</template>
</template>
js
handleClick(){
let listElements = [...this.template.querySelectorAll('lightning-dual-listbox')];
for(let item in listElements){
listElements[item].selectedIndex = 0;
}
}
render
I would like the value "Richard Jones" to be highlighted upon component rendering (or upon button "do select" click to begin with).
Thanks for your answers