feat(list-box-menu-item): set title attribute if label is truncated

This commit is contained in:
Eric Liu 2022-05-28 10:03:10 -07:00
commit 53acd58117

View file

@ -4,6 +4,11 @@
/** Set to `true` to enable the highlighted state */ /** Set to `true` to enable the highlighted state */
export let highlighted = false; export let highlighted = false;
let ref = null;
$: isTruncated = ref?.offsetWidth < ref?.scrollWidth;
$: title = isTruncated ? ref?.innerText : undefined;
</script> </script>
<div <div
@ -15,7 +20,11 @@
on:mouseenter on:mouseenter
on:mouseleave on:mouseleave
> >
<div class:bx--list-box__menu-item__option="{true}"> <div
bind:this="{ref}"
title="{title}"
class:bx--list-box__menu-item__option="{true}"
>
<slot /> <slot />
</div> </div>
</div> </div>