menumenu_openMDC

Tooltip Box

descriptionREADMEwidgetsDemo

Material Design 3 tooltip-box component (mdc-tooltip-box).

Usage

<mdc-tooltip-box></mdc-tooltip-box>

Properties

Property Type Default
placement TooltipBoxPlacement 'bottom'
offset number 8
showDelay number 400
hideDelay number 0
trigger TooltipBoxTriggerMode 'hover'
open boolean false
disableFlip boolean false
quick boolean false

Slots

  • default
  • tooltip

Caret

Code
<mdc-tooltip-box placement="top" caret>
    <mdc-button variant="filled"><span>Plain with Caret (Top)</span></mdc-button>
    <mdc-tooltip slot="tooltip">Add to favorites</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="bottom" caret>
    <mdc-button variant="outlined"><span>Plain with Caret (Bottom)</span></mdc-button>
    <mdc-tooltip slot="tooltip">Share this item</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="bottom" caret persistent trigger="click">
    <mdc-button variant="tonal"><span>Rich Persistent with Caret (Click)</span></mdc-button>
    <mdc-tooltip slot="tooltip" rich>
        <span slot="headline">Permissions updated</span>
        <span>Anyone with the link can now view and comment on this file.</span>
        <mdc-button slot="actions" variant="text"><span>Learn more</span></mdc-button>
    </mdc-tooltip>
</mdc-tooltip-box>

Message

Code
<mdc-tooltip-box>
    <mdc-button variant="filled"><span>Hover for tooltip</span></mdc-button>
    <mdc-tooltip slot="tooltip">This is a plain tooltip</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box>
    <mdc-button variant="outlined"><span>Another button</span></mdc-button>
    <mdc-tooltip slot="tooltip">Short tip</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box>
    <mdc-icon-button icon="delete"></mdc-icon-button>
    <mdc-tooltip slot="tooltip">Delete this item</mdc-tooltip>
</mdc-tooltip-box>

Placement

Code
<mdc-tooltip-box placement="top">
    <mdc-button variant="filled"><span>Top</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="top"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="top-start">
    <mdc-button variant="filled"><span>Top Start</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="top-start"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="top-end">
    <mdc-button variant="filled"><span>Top End</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="top-end"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="bottom">
    <mdc-button variant="filled"><span>Bottom</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="bottom"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="bottom-start">
    <mdc-button variant="filled"><span>Bottom Start</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="bottom-start"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="bottom-end">
    <mdc-button variant="filled"><span>Bottom End</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="bottom-end"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="left">
    <mdc-button variant="filled"><span>Left</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="left"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="left-start">
    <mdc-button variant="filled"><span>Left Start</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="left-start"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="left-end">
    <mdc-button variant="filled"><span>Left End</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="left-end"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="right">
    <mdc-button variant="filled"><span>Right</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="right"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="right-start">
    <mdc-button variant="filled"><span>Right Start</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="right-start"</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="right-end">
    <mdc-button variant="filled"><span>Right End</span></mdc-button>
    <mdc-tooltip slot="tooltip">placement="right-end"</mdc-tooltip>
</mdc-tooltip-box>

Rich

Code
<mdc-tooltip-box placement="bottom">
    <mdc-button variant="filled"><span>Rich with headline</span></mdc-button>
    <mdc-tooltip slot="tooltip" rich>
        <span slot="headline">Sync complete</span>
        <span>All 24 files have been uploaded to the cloud.</span>
        <mdc-button slot="actions"><span>Undo</span></mdc-button>
    </mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="bottom">
    <mdc-button variant="outlined"><span>Rich no headline</span></mdc-button>
    <mdc-tooltip slot="tooltip" rich>
        <span>This tooltip has no headline, only content and actions.</span>
        <mdc-button slot="actions"><span>OK</span></mdc-button>
    </mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box placement="bottom">
    <mdc-icon-button icon="info"></mdc-icon-button>
    <mdc-tooltip slot="tooltip" rich>
        <span slot="headline">About this feature</span>
        <span>This feature enables automatic syncing across all your devices.</span>
    </mdc-tooltip>
</mdc-tooltip-box>

Trigger

Code
<mdc-tooltip-box>
    <mdc-button variant="filled"><span>Auto trigger (default: hover + focus + long-press)</span></mdc-button>
    <mdc-tooltip slot="tooltip">Shows on hover, keyboard focus, or touch long-press</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box trigger="hover">
    <mdc-button variant="outlined"><span>Hover only</span></mdc-button>
    <mdc-tooltip slot="tooltip">Shows on pointer enter, hides on pointer leave</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box trigger="focus">
    <mdc-button variant="outlined"><span>Focus only</span></mdc-button>
    <mdc-tooltip slot="tooltip">Shows on focus in, hides on focus out. Tab to this button.</mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box trigger="click" persistent>
    <mdc-button variant="tonal"><span>Click + Persistent</span></mdc-button>
    <mdc-tooltip slot="tooltip" rich>
        <span slot="headline">Persistent Tooltip</span>
        <span>Stays open until you press Escape or click outside.</span>
    </mdc-tooltip>
</mdc-tooltip-box>

<mdc-tooltip-box trigger="manual" id="manual-tooltip-box">
    <mdc-button variant="filled" id="manual-btn"><span>Manual trigger</span></mdc-button>
    <mdc-tooltip slot="tooltip">Controlled via JavaScript</mdc-tooltip>
</mdc-tooltip-box>

<script>
    (() => {
        const root = document.currentScript?.getRootNode?.() ?? document
        const tb = root.getElementById ? root.getElementById('manual-tooltip-box') : root.querySelector('#manual-tooltip-box')
        const btn = root.getElementById ? root.getElementById('manual-btn') : root.querySelector('#manual-btn')
        btn?.addEventListener('click', () => {
            if (tb.open) {
                tb.hide()
            } else {
                tb.show()
            }
        })
    })()
</script>