탐색

v2.1.0
오버레이

툴팁

호버하거나 포커스를 옮기거나 길게 누르면 나타나는 잉크색 표면의 짧은 레이블입니다.

이 페이지의 내용

툴팁은 컨트롤의 이름이나 단축키를 보여 주는 잉크색 표면의 짧은 레이블입니다. 툴팁은 힌트 팝오버로 동작합니다. 레이블에는 popover="hint"와 .tooltip을, 컨트롤에는 interestfor를 지정하세요. 브라우저는 호버하거나 키보드로 포커스를 옮기면 잠시 후 툴팁을 표시하고, 터치 화면에서는 길게 누르면 표시합니다. Esc를 누르면 툴팁을 숨기며, 이미 열린 메뉴는 닫지 않습니다. CSS 앵커 위치 지정으로 툴팁을 컨트롤 위쪽 가운데에 배치합니다.

툴팁

<button type="button" class="btn btn-square" interestfor="tip-search" aria-label="Search">  <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">    <circle cx="7" cy="7" r="4.5" /><path d="M10.182 10.182L14 14" />  </svg></button><button type="button" class="btn btn-square" interestfor="tip-filter" aria-label="Filter">  <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">    <path d="M4.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" />  </svg></button><div id="tip-search" popover="hint" class="tooltip">Search <kbd class="kbd">/</kbd></div><div id="tip-filter" popover="hint" class="tooltip">Filter <kbd class="kbd">F</kbd></div>
import SearchIcon from '@master/icons-react/native/16/soft/search'import FilterIcon from '@master/icons-react/native/16/soft/filter'<>  <button type="button" className="btn btn-square" {...{ interestfor: 'tip-search' }} aria-label="Search">    <SearchIcon className="icon" />  </button>  <button type="button" className="btn btn-square" {...{ interestfor: 'tip-filter' }} aria-label="Filter">    <FilterIcon className="icon" />  </button>  <div id="tip-search" popover="hint" className="tooltip">Search <kbd className="kbd">/</kbd></div>  <div id="tip-filter" popover="hint" className="tooltip">Filter <kbd className="kbd">F</kbd></div></>
<script>  import SearchIcon from '@master/icons-svelte/native/16/soft/search'  import FilterIcon from '@master/icons-svelte/native/16/soft/filter'</script><button type="button" class="btn btn-square" interestfor="tip-search" aria-label="Search">  <SearchIcon class="icon" /></button><button type="button" class="btn btn-square" interestfor="tip-filter" aria-label="Filter">  <FilterIcon class="icon" /></button><div id="tip-search" popover="hint" class="tooltip">Search <kbd class="kbd">/</kbd></div><div id="tip-filter" popover="hint" class="tooltip">Filter <kbd class="kbd">F</kbd></div>
<script setup>import SearchIcon from '@master/icons-vue/native/16/soft/search'import FilterIcon from '@master/icons-vue/native/16/soft/filter'</script><template>  <button type="button" class="btn btn-square" interestfor="tip-search" aria-label="Search">    <SearchIcon class="icon" />  </button>  <button type="button" class="btn btn-square" interestfor="tip-filter" aria-label="Filter">    <FilterIcon class="icon" />  </button>  <div id="tip-search" popover="hint" class="tooltip">Search <kbd class="kbd">/</kbd></div>  <div id="tip-filter" popover="hint" class="tooltip">Filter <kbd class="kbd">F</kbd></div></template>
버튼에 포인터를 올리거나 Tab 키로 버튼에 포커스를 옮기세요.

#배치

툴팁은 컨트롤에서 위로 6px 떨어진 곳에 표시되며, 위쪽에 공간이 부족하면 아래쪽으로 옮겨갑니다. 상단 바의 컨트롤에는 아래쪽 공간을 우선하는 tooltip-bottom을 사용하세요.

아래쪽 배치

<button type="button" class="btn" interestfor="tip-deploy">Deploy</button><div id="tip-deploy" popover="hint" class="tooltip tooltip-bottom">  Ships the main branch to production</div>
<>  <button type="button" className="btn" {...{ interestfor: 'tip-deploy' }}>Deploy</button>  <div id="tip-deploy" popover="hint" className="tooltip tooltip-bottom">    Ships the main branch to production  </div></>
<button type="button" class="btn" interestfor="tip-deploy">Deploy</button><div id="tip-deploy" popover="hint" class="tooltip tooltip-bottom">  Ships the main branch to production</div>
<template>  <button type="button" class="btn" interestfor="tip-deploy">Deploy</button>  <div id="tip-deploy" popover="hint" class="tooltip tooltip-bottom">    Ships the main branch to production  </div></template>

#내용

툴팁은 몇 단어로 짧게 작성하세요. 텍스트는 너비 16rem에서 줄바꿈되며 각 줄의 길이가 균형을 이룹니다. 툴팁은 내부 kbd에 쓰이는 디자인 토큰을 조정하므로, 별도 변형을 적용하지 않아도 잉크색 표면에서 잘 읽힙니다. 링크나 양식처럼 사용자가 조작해야 하는 내용에는 팝오버를 사용하세요.

#접근성

  • 툴팁은 컨트롤의 이름에 설명을 덧붙이며, 이름 자체는 별도로 제공해야 합니다. 터치 화면에서는 길게 눌러야 툴팁이 표시되므로 아이콘만 있는 버튼의 aria-label을 유지하세요.
  • 브라우저가 툴팁을 해당 컨트롤에 연결하므로 보조 기술은 툴팁을 설명으로 전달합니다.
  • Chrome과 Edge는 Interest Invokers를 지원합니다. 이 기능을 지원하지 않는 브라우저에서는 툴팁이 표시되지 않으며 컨트롤의 접근 가능한 이름은 유지됩니다. 해당 브라우저에서도 툴팁을 표시하려면 포인터와 포커스 이벤트 핸들러에서 showPopover()와 hidePopover()를 호출하세요. 같은 스타일시트를 사용합니다.

#React, Svelte 및 Vue

tooltip 컴포넌트는 id로 컨트롤과 툴팁을 연결합니다. 컨트롤은 페이지의 마크업을 그대로 사용하고, 툴팁은 브라우저가 표시합니다. npx master-ui add tooltip 명령으로 컴포넌트를 프로젝트에 복사하세요. 컴포넌트의 구조와 사용법은 React, Svelte 및 Vue 문서에서 확인할 수 있습니다.

ui/tooltip.tsx
import { useId, type ComponentProps, type ReactNode } from 'react'export interface TooltipProps extends Omit<ComponentProps<'div'>, 'popover'> {  /** The control the tooltip names: spread what it is given on a button or a link of your own. */  trigger: (attributes: { interestfor: string }) => ReactNode}/** * A tooltip. The browser shows it on hover and on focus and places it; this component only joins the * control to its label. The children are the label. The control keeps its own accessible name. */export function Tooltip({ trigger, className, id, children, ...root }: TooltipProps) {  const generated = useId()  const name = id ?? generated  return (    <>      {trigger({ interestfor: name })}      <div id={name} popover="hint" className={className ? `tooltip ${className}` : 'tooltip'} {...root}>{children}</div>    </>  )}
ui/Tooltip.svelte
<script lang="ts" module>  import type { Snippet } from 'svelte'  import type { HTMLAttributes } from 'svelte/elements'  export interface TooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'popover'> {    /** The control the tooltip names: spread what it is given on a button or a link of your own. */    trigger: Snippet<[{ interestfor: string }]>  }</script><script lang="ts">  let { trigger, class: className, id, children, ...root }: TooltipProps = $props()  const generated = $props.id()  const name = $derived(id ?? generated)</script><!--  @component  A tooltip. The browser shows it on hover and on focus and places it; this component only joins the  control to its label. The children are the label. The control keeps its own accessible name.-->{@render trigger({ interestfor: name })}<div id={name} popover="hint" class={['tooltip', className]} {...root}>{@render children?.()}</div>
ui/Tooltip.vue
<script setup lang="ts">import { computed, useId } from 'vue'defineOptions({ inheritAttrs: false })const { id } = defineProps<{  id?: string}>()defineSlots<{  /** The control the tooltip names: bind what it is given on a button or a link of your own. */  trigger: (attributes: { interestfor: string }) => unknown  default?: () => unknown}>()/* * A tooltip. The browser shows it on hover and on focus and places it; this component only joins the * control to its label. The default slot is the label. The control keeps its own accessible name. */const generated = useId()const name = computed(() => id ?? generated)</script><template>  <slot name="trigger" v-bind="{ interestfor: name }" />  <div :id="name" popover="hint" class="tooltip" v-bind="$attrs"><slot /></div></template>

#클래스

클래스설명
tooltip레이블은 popover="hint"가 지정된 요소에 둡니다. popover 속성이 없으면 표시되지 않습니다. 컨트롤 위쪽 가운데에 --anchored-gap (6px)만큼 떨어져 표시되며, 위쪽 공간이 부족하면 아래로 이동합니다. 너비가 16rem에 이르면 줄이 바뀝니다. 내부의 kbd는 별도 변형 없이 잉크 표면에 표시됩니다.
tooltip-bottom컨트롤 아래쪽 공간을 우선 사용합니다. 상단 바에 있는 컨트롤에 적합합니다적용할 클래스는 tooltip입니다

#사용자 지정 속성

속성기본값설명
--anchored-gap표면과 그 표면을 연 컨트롤 사이 간격. 값을 지정하지 않으면 6px입니다.tooltip에 설정합니다

#소스 코드

@master/ui/components/tooltip.css
/* * Tooltip: a short label in ink, shown when a control is hovered, focused or long-pressed. * It is a hint popover: popover="hint" on the tooltip and interestfor on the control, so the browser handles * the delay, the keys and touch, and it never closes a menu that is already open. Anchor positioning centers * it above the control and flips it below when there is no room. */@layer components.ui {  .tooltip {    @apply --on-ink;    /* What it holds and cuts a ring out of it (a citation's fill) reads the tip's own face, not the page's. */    --surface-color: var(--color-surface-tip);    --anchored-block: block-start;    --anchored-inline: span-all;    /*     * It appears often and under the pointer, so it arrives quicker than a popover and from nearer its size, and     * leaves quicker still.     */    --pop-scale: .985;    --pop-enter: calc(var(--duration-quick) * .75);    --pop-leave: calc(var(--duration-quick) / 2);    overflow-wrap: anywhere;    width: max-content;    max-width: min(16rem, calc(100vw - 1rem));    padding: .3125rem .5rem;    border: 0;    border-radius: calc((var(--radius-chip) + 1px) * var(--corner-scale));    corner-shape: var(--corner-shape);    overflow: visible;    background: var(--color-surface-tip);    color: light-dark(var(--color-text-inverse), var(--color-text-strong));    box-shadow: var(--shadow-tip);    font: 400 .75rem/1.35 var(--font-family-sans);    font-feature-settings: inherit;    text-align: center;    text-wrap: balance;    transform-origin: bottom;    @apply --anchored;    @apply --pop;    /* Prefer the space below the control. */    &.tooltip-bottom {      --anchored-block: block-end;      transform-origin: top;    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }}