Ok, got it.
If you are using a vanilla select, you can try the following.
Worked for me perfectly.
The key is to wrap your <option>
with a <span>
to get the texts actual pixel width
Html:
<select id="select" (change)="debug()" style="max-width:200px">
<option>
<span>
Blalalalalalalalallalaalalalalalalalallaallalalalalaal
</span>
</option>
<option>
<span>
Blalalallalalalalalalalalalallaal
</span>
</option>
<option>
<span>
Blalalalalala
</span>
</option>
</select>
TS:
debug() {
const el = document.querySelector('#select');
for (let i = 0; i < el['options'].length; i++) {
if (this.isEllipsisActive(el['options'][i])) {
console.log('cause offset', el['options'][i]);
}
}
}
isEllipsisActive(e) {
if (e.children[0].scrollWidth > document.querySelector('#select').scrollWidth) {
return true;
}
return false;
}