mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
feat: set title attribute in CheckBox
, MultiSelect
, Dropdown
, ComboBox
if label is truncated (#1317)
* feat(checkbox): set title attribute if label is truncated * feat(list-box-menu-item): set title attribute if label is truncated
This commit is contained in:
parent
90477c4d0e
commit
40e18fbc88
2 changed files with 16 additions and 1 deletions
|
@ -62,6 +62,11 @@
|
|||
$: useGroup = Array.isArray(group);
|
||||
$: checked = useGroup ? group.includes(value) : checked;
|
||||
$: dispatch("check", checked);
|
||||
|
||||
let refLabel = null;
|
||||
|
||||
$: isTruncated = refLabel?.offsetWidth < refLabel?.scrollWidth;
|
||||
$: title = isTruncated ? refLabel?.innerText : title;
|
||||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
||||
|
@ -109,6 +114,7 @@
|
|||
/>
|
||||
<label for="{id}" title="{title}" class:bx--checkbox-label="{true}">
|
||||
<span
|
||||
bind:this="{refLabel}"
|
||||
class:bx--checkbox-label-text="{true}"
|
||||
class:bx--visually-hidden="{hideLabel}"
|
||||
>
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
|
||||
/** Set to `true` to enable the highlighted state */
|
||||
export let highlighted = false;
|
||||
|
||||
let ref = null;
|
||||
|
||||
$: isTruncated = ref?.offsetWidth < ref?.scrollWidth;
|
||||
$: title = isTruncated ? ref?.innerText : undefined;
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
@ -15,7 +20,11 @@
|
|||
on:mouseenter
|
||||
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 />
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue