Tooltip คือข้อความสั้น ๆ บรรทัดเดียวที่อธิบาย control ที่มันครอบอยู่ เปิดเมื่อวางเมาส์ไว้บน control หรือเมื่อโฟกัสจากคีย์บอร์ดมาถึง และปิดเมื่อออกไป ใช้บอกชื่อไอคอนหรือให้คำแนะนำสั้น ๆ ห้ามใช้กับเนื้อหาที่ผู้ใช้ต้องอ่านหรือต้องกดเพื่อทำงานต่อ
HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center">
<ui-tooltip text="เก็บสำเนาที่ลงนามแล้วไว้ 10 ปี">
<ui-button kind="tertiary">นโยบายการเก็บเอกสาร</ui-button>
</ui-tooltip>
<ui-tooltip text="คัดลอกลิงก์" as-label>
<ui-button kind="ghost" icon-only>
<svg viewBox="0 0 16 16"><path d="M14 5v9H5V5h9m0-1H5a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1Z"/><path d="M2 9H1V2a1 1 0 0 1 1-1h7v1H2Z"/></svg>
</ui-button>
</ui-tooltip>
</div>
import { Copy as CopyIcon } from '@carbon/icons-react';
<UiTooltip text="เก็บสำเนาที่ลงนามแล้วไว้ 10 ปี">
<UiButton kind="tertiary">นโยบายการเก็บเอกสาร</UiButton>
</UiTooltip>
<UiTooltip text="คัดลอกลิงก์" asLabel>
<UiButton kind="ghost" iconOnly><CopyIcon /></UiButton>
</UiTooltip>
import { Copy as CopyIcon } from '@carbon/icons-react';
<Tooltip text="เก็บสำเนาที่ลงนามแล้วไว้ 10 ปี">
<Button kind="tertiary">นโยบายการเก็บเอกสาร</Button>
</Tooltip>
<Tooltip text="คัดลอกลิงก์" asLabel>
<Button kind="ghost" iconOnly><CopyIcon /></Button>
</Tooltip>
ติดตั้ง
npmshadcn · Web componentshadcn · React + Tailwindคัดลอกเองnpm install @purpurabog/ui
npx shadcn@4 add @kanok-ui/tooltip
npx shadcn@4 add @kanok-ui/tw-tooltip
# Web component
# 1. ติดตั้ง dependency
npm install lit@^3.3.0
# 2. คัดลอก "content" ของแต่ละไฟล์จาก
# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tooltip.json
# ไปไว้ที่ target ของมัน:
# components/ui/primitives/tooltip/tooltip.ts
# 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json):
# core-popup, shared-align, shared-element, shared-field, shared-position, tokens
# React + Tailwind
# 1. ติดตั้ง dependency
npm install @purpurabog/ui@^2.3.0
# 2. คัดลอก "content" ของแต่ละไฟล์จาก
# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-tooltip.json
# ไปไว้ที่ target ของมัน:
# components/ui/react-tw/tooltip.tsx
# 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json):
# core-position, tw-floating, tw-theme, tw-utils
npm ให้ทุก component จากแพ็กเกจ ส่วน shadcn คัดลอกซอร์สเข้าแอปของคุณแทน เป็นสำเนาที่ล็อกเวอร์ชันนี้และแก้เองได้ คำสั่ง shadcn ต้องตั้ง registry @kanok-ui ใน components.json ครั้งเดียวก่อน ดู ติดตั้ง
วิธีใช้
ครอบ element ที่รับโฟกัสได้หนึ่งตัว เช่น ปุ่มหรือลิงก์ แล้วใส่ข้อความใน text
HTMLReactReact + Tailwind<script type="module">import '@purpurabog/ui/tooltip';</script>
<ui-tooltip text="เก็บสำเนาที่ลงนามแล้วไว้ 10 ปี">
<ui-button kind="tertiary">นโยบายการเก็บเอกสาร</ui-button>
</ui-tooltip>
import { UiTooltip, UiButton } from '@purpurabog/ui/react';
<UiTooltip text="เก็บสำเนาที่ลงนามแล้วไว้ 10 ปี">
<UiButton kind="tertiary">นโยบายการเก็บเอกสาร</UiButton>
</UiTooltip>
import { Tooltip } from '@/components/ui/react-tw/tooltip';
import { Button } from '@/components/ui/react-tw/button';
<Tooltip text="เก็บสำเนาที่ลงนามแล้วไว้ 10 ปี">
<Button kind="tertiary">นโยบายการเก็บเอกสาร</Button>
</Tooltip>
| Component |
ใช้เมื่อ |
| Tooltip |
คำแนะนำสั้น ๆ เป็นข้อความล้วน หรือชื่อของไอคอน เปิดเมื่อชี้เมาส์และเมื่อโฟกัส และไม่มีอะไรให้กด |
| Toggletip |
คำอธิบายมีลิงก์หรือปุ่ม หรือควรเปิดค้างจนผู้ใช้ปิดเอง เปิดด้วยการคลิก |
| Definition tooltip |
คำในเนื้อความต้องมีคำนิยาม คำนั้นจะมีเส้นใต้แบบจุด |
| Popover |
เนื้อหาของคุณเอง (ตัวกรอง ฟอร์มเล็ก ๆ) ข้าง trigger |
ตำแหน่ง
กล่องข้อความเปิดเหนือ trigger (placement="top") ใช้ bottom, left และ right เพื่อย้ายตำแหน่ง ถ้าที่ไม่พอก็จะพลิกไปอีกฝั่ง align คือชื่อแบบ Carbon ของ attribute เดียวกัน
HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center">
<ui-tooltip text="เปิดด้านบน" placement="top"><ui-button kind="tertiary" size="sm">บน</ui-button></ui-tooltip>
<ui-tooltip text="เปิดด้านล่าง" placement="bottom"><ui-button kind="tertiary" size="sm">ล่าง</ui-button></ui-tooltip>
<ui-tooltip text="เปิดด้านซ้าย" placement="left"><ui-button kind="tertiary" size="sm">ซ้าย</ui-button></ui-tooltip>
<ui-tooltip text="เปิดด้านขวา" placement="right"><ui-button kind="tertiary" size="sm">ขวา</ui-button></ui-tooltip>
</div>
<UiTooltip text="เปิดด้านบน" placement="top"><UiButton kind="tertiary" size="sm">บน</UiButton></UiTooltip>
<UiTooltip text="เปิดด้านล่าง" placement="bottom"><UiButton kind="tertiary" size="sm">ล่าง</UiButton></UiTooltip>
<UiTooltip text="เปิดด้านซ้าย" placement="left"><UiButton kind="tertiary" size="sm">ซ้าย</UiButton></UiTooltip>
<UiTooltip text="เปิดด้านขวา" placement="right"><UiButton kind="tertiary" size="sm">ขวา</UiButton></UiTooltip>
<Tooltip text="เปิดด้านบน" placement="top"><Button kind="tertiary" size="sm">บน</Button></Tooltip>
<Tooltip text="เปิดด้านล่าง" placement="bottom"><Button kind="tertiary" size="sm">ล่าง</Button></Tooltip>
<Tooltip text="เปิดด้านซ้าย" placement="left"><Button kind="tertiary" size="sm">ซ้าย</Button></Tooltip>
<Tooltip text="เปิดด้านขวา" placement="right"><Button kind="tertiary" size="sm">ขวา</Button></Tooltip>
ชิดขอบต้นและขอบปลาย
เติม -start หรือ -end เพื่อให้กล่องชิดขอบด้านหนึ่งของ trigger แทนการอยู่กึ่งกลาง ใช้กับ trigger ที่อยู่ใกล้ขอบจอหรือขอบตาราง ลูกศรยังชี้ไปที่ trigger เหมือนเดิม ในหน้าที่อ่านจากขวาไปซ้าย start และ end จะสลับฝั่งกัน
ล่าง ชิดต้น
ล่าง ชิดปลาย
บน ชิดต้น
HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center">
<ui-tooltip text="ชิดขอบต้นของปุ่ม" placement="bottom-start"><ui-button kind="tertiary" size="sm">ล่าง ชิดต้น</ui-button></ui-tooltip>
<ui-tooltip text="ชิดขอบปลายของปุ่ม" placement="bottom-end"><ui-button kind="tertiary" size="sm">ล่าง ชิดปลาย</ui-button></ui-tooltip>
<ui-tooltip text="ชิดขอบต้น อยู่ด้านบน" placement="top-start"><ui-button kind="tertiary" size="sm">บน ชิดต้น</ui-button></ui-tooltip>
</div>
<UiTooltip text="ชิดขอบต้นของปุ่ม" placement="bottom-start">…</UiTooltip>
<UiTooltip text="ชิดขอบปลายของปุ่ม" placement="bottom-end">…</UiTooltip>
<UiTooltip text="ชิดขอบต้น อยู่ด้านบน" placement="top-start">…</UiTooltip>
<Tooltip text="ชิดขอบต้นของปุ่ม" placement="bottom-start">…</Tooltip>
<Tooltip text="ชิดขอบปลายของปุ่ม" placement="bottom-end">…</Tooltip>
<Tooltip text="ชิดขอบต้น อยู่ด้านบน" placement="top-start">…</Tooltip>
ตั้งชื่อปุ่มที่มีแต่ไอคอน
ปุ่มที่มีแต่ไอคอนไม่มีชื่อที่มองเห็น as-label (asLabel ใน React) ทำให้ข้อความเป็นชื่อสำหรับ accessibility ของปุ่ม และให้หน้าตาแบบ icon tooltip ของ Carbon คือ padding และลูกศรเล็กลง ห่างจากปุ่ม 8px <ui-icon-button> ทำเรื่องนี้ให้อยู่แล้วผ่าน label
HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center">
<ui-tooltip text="แก้ไขสัญญา" as-label>
<ui-button kind="ghost" icon-only>
<svg viewBox="0 0 16 16"><path d="m13.7 4.3-2-2a1 1 0 0 0-1.4 0L2 10.6V14h3.4l8.3-8.3a1 1 0 0 0 0-1.4ZM5 13H3v-2l6-6 2 2Zm7-7-2-2 1-1 2 2Z"/></svg>
</ui-button>
</ui-tooltip>
<ui-tooltip text="ทำสำเนาสัญญา" as-label>
<ui-button kind="ghost" icon-only>
<svg viewBox="0 0 16 16"><path d="M14 5v9H5V5h9m0-1H5a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1Z"/><path d="M2 9H1V2a1 1 0 0 1 1-1h7v1H2Z"/></svg>
</ui-button>
</ui-tooltip>
<ui-tooltip text="ลบสัญญา" as-label>
<ui-button kind="ghost" icon-only>
<svg viewBox="0 0 16 16"><path d="M6 6h1v6H6zm3 0h1v6H9z"/><path d="M2 3v1h1v10a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4h1V3Zm2 11V4h8v10ZM6 1h4v1H6z"/></svg>
</ui-button>
</ui-tooltip>
</div>
import { Copy as CopyIcon, Edit as EditIcon, TrashCan as TrashCanIcon } from '@carbon/icons-react';
<UiTooltip text="แก้ไขสัญญา" asLabel>
<UiButton kind="ghost" iconOnly><EditIcon /></UiButton>
</UiTooltip>
<UiTooltip text="ทำสำเนาสัญญา" asLabel>
<UiButton kind="ghost" iconOnly><CopyIcon /></UiButton>
</UiTooltip>
<UiTooltip text="ลบสัญญา" asLabel>
<UiButton kind="ghost" iconOnly><TrashCanIcon /></UiButton>
</UiTooltip>
import { Copy as CopyIcon, Edit as EditIcon, TrashCan as TrashCanIcon } from '@carbon/icons-react';
<Tooltip text="แก้ไขสัญญา" asLabel>
<Button kind="ghost" iconOnly><EditIcon /></Button>
</Tooltip>
<Tooltip text="ทำสำเนาสัญญา" asLabel>
<Button kind="ghost" iconOnly><CopyIcon /></Button>
</Tooltip>
<Tooltip text="ลบสัญญา" asLabel>
<Button kind="ghost" iconOnly><TrashCanIcon /></Button>
</Tooltip>
แบบเล็ก
small ให้หน้าตาแบบกะทัดรัดเหมือน as-label แต่ข้อความยังเป็นคำอธิบายอยู่ ใช้กับคำแนะนำสั้น ๆ บน control ที่มีชื่อที่มองเห็นอยู่แล้ว
HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center">
<ui-tooltip text="Ctrl+S" small>
<ui-button kind="secondary" size="sm">บันทึกร่าง</ui-button>
</ui-tooltip>
<ui-tooltip text="ไปที่ตารางด้านล่าง" small placement="bottom">
<a href="#คีย์บอร์ด">คีย์บอร์ด</a>
</ui-tooltip>
</div>
<UiTooltip text="Ctrl+S" small>
<UiButton kind="secondary" size="sm">บันทึกร่าง</UiButton>
</UiTooltip>
<UiTooltip text="ไปที่ตารางด้านล่าง" small placement="bottom">
<a href="#คีย์บอร์ด">คีย์บอร์ด</a>
</UiTooltip>
<Tooltip text="Ctrl+S" small>
<Button kind="secondary" size="sm">บันทึกร่าง</Button>
</Tooltip>
<Tooltip text="ไปที่ตารางด้านล่าง" small placement="bottom">
<a href="#คีย์บอร์ด">คีย์บอร์ด</a>
</Tooltip>
Trigger อะไรก็ได้ที่รับโฟกัส
Trigger เป็น element ใดก็ได้ที่รับโฟกัสได้ เช่น ปุ่มของเรา <button> ธรรมดา หรือลิงก์ ให้ครอบแค่ตัวเดียว ข้อความจะต่อท้ายคำอธิบายเดิมของ trigger (aria-describedby) โดยไม่แทนที่ <span> ธรรมดาหรือไอคอนไม่ได้รับโฟกัสจากคีย์บอร์ด ผู้ใช้คีย์บอร์ดจึงไม่มีทางเห็น tooltip ของมัน ให้ครอบปุ่มแทน
HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center">
<ui-tooltip text="แก้ไขล่าสุด 12 มีนาคม 2569 โดยสมชาย">
<button type="button">ฉบับที่ 3</button>
</ui-tooltip>
<ui-tooltip text="สัญญา CN-2026-0142 เช่าสำนักงานสีลม" placement="bottom">
<a href="#trigger-อะไรก็ได้ที่รับโฟกัส">CN-2026-0142</a>
</ui-tooltip>
</div>
<UiTooltip text="แก้ไขล่าสุด 12 มีนาคม 2569 โดยสมชาย">
<button type="button">ฉบับที่ 3</button>
</UiTooltip>
<UiTooltip text="สัญญา CN-2026-0142 เช่าสำนักงานสีลม" placement="bottom">
<a href="/contracts/0142">CN-2026-0142</a>
</UiTooltip>
<Tooltip text="แก้ไขล่าสุด 12 มีนาคม 2569 โดยสมชาย">
<button type="button">ฉบับที่ 3</button>
</Tooltip>
<Tooltip text="สัญญา CN-2026-0142 เช่าสำนักงานสีลม" placement="bottom">
<a href="/contracts/0142">CN-2026-0142</a>
</Tooltip>
อธิบายว่าทำไมปุ่มกดไม่ได้
ปุ่มที่ disabled รับโฟกัสไม่ได้ ผู้ใช้คีย์บอร์ดจึงไม่เห็น tooltip ของมัน ให้ใช้ disabled-focusable ที่ปุ่มแทน ปุ่มจะดูและทำงานเหมือนปิดใช้งาน แต่ยังอยู่ในลำดับ Tab และ tooltip บอกเหตุผลได้
ลงนามสัญญา
HTMLReactReact + Tailwind<ui-tooltip text="เฉพาะผู้อนุมัติเท่านั้นที่ลงนามได้ ติดต่อคุณอนัญญา ฝ่ายกฎหมาย" placement="right">
<ui-button disabled-focusable>ลงนามสัญญา</ui-button>
</ui-tooltip>
<UiTooltip text="เฉพาะผู้อนุมัติเท่านั้นที่ลงนามได้ ติดต่อคุณอนัญญา ฝ่ายกฎหมาย" placement="right">
<UiButton disabledFocusable>ลงนามสัญญา</UiButton>
</UiTooltip>
<Tooltip text="เฉพาะผู้อนุมัติเท่านั้นที่ลงนามได้ ติดต่อคุณอนัญญา ฝ่ายกฎหมาย" placement="right">
<Button disabledFocusable>ลงนามสัญญา</Button>
</Tooltip>
ข้อความยาว
กล่องขยายตามข้อความได้กว้างสุด 288px แล้วจึงขึ้นบรรทัดใหม่ เขียนให้จบในหนึ่งหรือสองประโยค เพราะ tooltip เลื่อนอ่านไม่ได้ และหายไปเมื่อเมาส์ออก คำอธิบายที่ยาวกว่านี้ควรอยู่ใน toggletip หรือบนหน้าเลย
การเก็บเอกสารทำงานอย่างไร
HTMLReactReact + Tailwind<ui-tooltip text="ระยะเวลาเก็บเอกสารเริ่มนับจากวันที่คู่สัญญาคนสุดท้ายลงนาม ครบ 10 ปีแล้วสำเนาจะย้ายไปที่คลังเอกสาร ซึ่งเปิดดูได้เฉพาะฝ่ายกฎหมาย" placement="bottom">
<ui-button kind="tertiary">การเก็บเอกสารทำงานอย่างไร</ui-button>
</ui-tooltip>
<UiTooltip text="ระยะเวลาเก็บเอกสารเริ่มนับจากวันที่คู่สัญญาคนสุดท้ายลงนาม ครบ 10 ปีแล้วสำเนาจะย้ายไปที่คลังเอกสาร ซึ่งเปิดดูได้เฉพาะฝ่ายกฎหมาย" placement="bottom">
<UiButton kind="tertiary">การเก็บเอกสารทำงานอย่างไร</UiButton>
</UiTooltip>
<Tooltip text="ระยะเวลาเก็บเอกสารเริ่มนับจากวันที่คู่สัญญาคนสุดท้ายลงนาม ครบ 10 ปีแล้วสำเนาจะย้ายไปที่คลังเอกสาร ซึ่งเปิดดูได้เฉพาะฝ่ายกฎหมาย" placement="bottom">
<Button kind="tertiary">การเก็บเอกสารทำงานอย่างไร</Button>
</Tooltip>
ในกล่องที่ตัดเนื้อหา
กล่องข้อความเปิดใน top layer ของ browser กล่องแม่ที่มี overflow: hidden หรือสูงไม่พอจึงตัดมันไม่ได้ ลองชี้เมาส์ที่ปุ่มในกล่องเตี้ย ๆ ด้านล่าง
HTMLReactReact + Tailwind<div style="overflow: hidden; height: 56px; padding: 8px; border: 1px solid var(--ui-hairline)">
<ui-tooltip text="กล่องนี้ซ่อนส่วนที่ล้น แต่ tooltip ยังแสดงครบ" placement="bottom">
<ui-button kind="tertiary" size="sm">สถานะสัญญา</ui-button>
</ui-tooltip>
</div>
<div style={{ overflow: 'hidden', height: 56 }}>
<UiTooltip text="กล่องนี้ซ่อนส่วนที่ล้น แต่ tooltip ยังแสดงครบ" placement="bottom">
<UiButton kind="tertiary" size="sm">สถานะสัญญา</UiButton>
</UiTooltip>
</div>
<div className="h-14 overflow-hidden">
<Tooltip text="กล่องนี้ซ่อนส่วนที่ล้น แต่ tooltip ยังแสดงครบ" placement="bottom">
<Button kind="tertiary" size="sm">สถานะสัญญา</Button>
</Tooltip>
</div>
เปิดค้างไว้: "คัดลอกแล้ว"
open ทำให้กล่องแสดง เมื่อใช้คู่กับ pinned กล่องจะเปิดค้างไม่ว่าเมาส์ โฟกัส การคลิก หรือ Esc จะเป็นอย่างไร จนกว่าคุณจะเอา open ออก ใช้กับข้อความยืนยันสั้น ๆ แบบเดียวกับปุ่มคัดลอกของ Carbon ลองคลิกเลขที่สัญญาด้านล่าง
CN-2026-0142
HTMLReactReact + Tailwind<ui-tooltip id="tooltip-copy" text="คัดลอกเลขที่สัญญา" small>
<ui-button id="tooltip-copy-button" kind="ghost">CN-2026-0142</ui-button>
</ui-tooltip>
<script type="module">
const tip = document.getElementById('tooltip-copy');
const button = document.getElementById('tooltip-copy-button');
let timer;
button.addEventListener('click', async () => {
await navigator.clipboard?.writeText('CN-2026-0142').catch(() => {});
tip.text = 'คัดลอกแล้ว';
tip.pinned = true;
tip.open = true;
clearTimeout(timer);
timer = setTimeout(() => {
tip.pinned = false;
tip.open = false;
tip.text = 'คัดลอกเลขที่สัญญา';
}, 2000);
});
</script>
const [copied, setCopied] = useState(false);
const copy = async () => {
await navigator.clipboard.writeText('CN-2026-0142');
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
<UiTooltip text={copied ? 'คัดลอกแล้ว' : 'คัดลอกเลขที่สัญญา'} small open={copied} pinned={copied}>
<UiButton kind="ghost" onClick={copy}>CN-2026-0142</UiButton>
</UiTooltip>
// เปิดเฉพาะตอนคัดลอกแล้ว ถ้าเป็น undefined การชี้เมาส์และโฟกัสเป็นตัวตัดสิน
<Tooltip text={copied ? 'คัดลอกแล้ว' : 'คัดลอกเลขที่สัญญา'} small open={copied ? true : undefined}>
<Button kind="ghost" onClick={copy}>CN-2026-0142</Button>
</Tooltip>
copy และ copied เหมือนกันทั้งสองแบบของ React ส่วน React + Tailwind ไม่มี pinned ระหว่างที่ตั้ง open ไว้ การชี้เมาส์และโฟกัสจะแค่รายงานผ่าน onOpenChange
คีย์บอร์ด
| ปุ่ม |
ผลลัพธ์ |
| Tab |
โฟกัสมาถึง trigger แล้ว tooltip เปิด โฟกัสออกไปแล้วปิด |
| Esc |
ปิดเฉพาะ tooltip โฟกัสยังอยู่ที่ trigger และ modal ที่ครอบอยู่ยังเปิดอยู่ |
| Enter, Space |
สั่งงาน trigger แล้วปิด tooltip เพื่อไม่ให้บังผลลัพธ์ |
การคลิกเมาส์ทำให้ trigger ได้โฟกัสโดยไม่เปิด tooltip ซ้ำ เพราะตอนชี้เมาส์ก็แสดงไปแล้ว
Accessibility
- กล่องมี
role="tooltip" ข้อความเป็นคำอธิบาย (accessible description) ของ trigger หรือถ้ามี as-label จะเป็นชื่อ (accessible name) screen reader อ่านได้โดยไม่ต้องให้กล่องแสดง
- ทำตาม WCAG 1.4.13 เลื่อนเมาส์ไปบนกล่องได้โดยกล่องไม่ปิด และกด Esc เพื่อปิดได้
- ห้ามใส่ลิงก์ ปุ่ม หรืออะไรก็ตามที่ต้องกดไว้ใน tooltip เพราะไม่มีใครกดถึง ให้ใช้ toggletip หรือ popover
- ข้อความต้องไม่ใช่ที่เดียวที่มีข้อมูลที่ผู้ใช้ต้องรู้เพื่อทำงานให้เสร็จ จอสัมผัสไม่มีการชี้เมาส์
ต้องการแค่พฤติกรรมโดยไม่มี style: Headless Tooltip
API
สร้างจากแพ็กเกจโดยตรง ใน React ส่ง property เป็น prop ชื่อเดียวกัน ส่วน event ก็เป็น prop เช่นกัน (ดูคอลัมน์ React)
Attribute
| Attribute |
Property |
ชนิด |
ค่าเริ่มต้น |
คำอธิบาย |
align |
|
|
|
Carbon's name for placement (same values) |
text |
text |
string |
'' |
|
placement |
placement |
TooltipPlacement |
'top' |
|
as-label |
asLabel |
boolean |
false |
Use the text as the trigger's accessible name instead of its description. |
small |
small |
boolean |
false |
The icon tooltip's look (as as-label: 8px off, 2px / 16px padding, 8×4 caret) without naming the trigger. |
open |
open |
boolean |
false |
Whether the bubble is showing. Hover / focus manage it; set it yourself together with pinned. |
pinned |
pinned |
boolean |
false |
Keep the bubble open regardless of hover, focus, clicks and Escape — for a confirmation such as "Copied!" (Carbon copy button). While pinned, only open closes it. |
Property
| Property |
ชนิด |
คำอธิบาย |
anchor |
HTMLElement | null |
The element the bubble points at, listens to and names / describes, instead of the slotted trigger — for a focusable host that renders its tooltip in its own shadow root (an icon-only content switcher item). |
Method
| Method |
คำอธิบาย |
focus(options) |
Focus the slotted trigger (delegatesFocus does not reach slotted light DOM). |
Slot
| Slot |
คำอธิบาย |
| (ค่าเริ่มต้น) |
The trigger (one focusable element, e.g. <ui-button>) |
CSS part
| Part |
คำอธิบาย |
bubble |
The tooltip bubble |
caret |
The arrow pointing at the trigger |
CSS custom property
| Custom property |
ค่าเริ่มต้น |
คำอธิบาย |
--ui-tooltip-radius |
|
Corner radius of the bubble (default --ui-radius-xs) |