Update button tooltip to remove wrapper div and place tooltip inside button element

This commit is contained in:
Andrew Kingston 2022-02-15 12:01:50 +00:00
parent 3b69862b56
commit 69bc9bf9fc
1 changed files with 40 additions and 54 deletions

View File

@ -17,8 +17,7 @@
let showTooltip = false let showTooltip = false
</script> </script>
<div class:container={!!tooltip}> <button
<button
class:spectrum-Button--cta={cta} class:spectrum-Button--cta={cta}
class:spectrum-Button--primary={primary} class:spectrum-Button--primary={primary}
class:spectrum-Button--secondary={secondary} class:spectrum-Button--secondary={secondary}
@ -31,7 +30,7 @@
on:click|preventDefault on:click|preventDefault
on:mouseover={() => (showTooltip = true)} on:mouseover={() => (showTooltip = true)}
on:mouseleave={() => (showTooltip = false)} on:mouseleave={() => (showTooltip = false)}
> >
{#if icon} {#if icon}
<svg <svg
class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}" class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}"
@ -57,25 +56,16 @@
</svg> </svg>
</div> </div>
{/if} {/if}
</button>
{#if showTooltip && tooltip} {#if showTooltip && tooltip}
<div class="position">
<div class="tooltip"> <div class="tooltip">
<Tooltip textWrapping={true} direction={"bottom"} text={tooltip} /> <Tooltip textWrapping={true} direction={"bottom"} text={tooltip} />
</div> </div>
</div>
{/if} {/if}
</div> </button>
<style> <style>
button { button {
width: 100%; position: relative;
}
.container {
display: flex;
align-items: center;
flex-direction: column;
} }
.spectrum-Button-label { .spectrum-Button-label {
white-space: nowrap; white-space: nowrap;
@ -93,12 +83,8 @@
width: 160px; width: 160px;
text-align: center; text-align: center;
transform: translateX(-50%); transform: translateX(-50%);
top: -5px; left: 50%;
} top: calc(100% - 3px);
.position {
position: relative;
width: 0;
height: 0;
} }
.tooltip-icon { .tooltip-icon {
padding-left: var(--spacing-m); padding-left: var(--spacing-m);