본문으로 건너뛰기Skip to content
예제 첫화면Examples home

말풍선 위치와 동작 고르기Choose where and how tooltips appear

tooltipOptions로 말풍선 위치(대상 기준·마우스 근처·위·아래), 마우스 따라가기, 사라짐 지연, 말풍선 위로 포인터 옮기기, 키보드 표시를 정해요. 컬럼의 tooltipRenderer는 말풍선 안을 DOM으로 채워요.tooltipOptions sets placement (near the target, near the pointer, above, below), pointer following, hide delay, moving the pointer onto the tip and keyboard display. A column's tooltipRenderer fills the tip with DOM.

활용Intermediate
직접 써 보기Live preview말풍선 위치와 동작 고르기Choose where and how tooltips appear

코드Code

탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.

이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<div id="app">
  <div class="toolbar">
    <select aria-label="말풍선 방식" id="mode">
      <option value="default" selected>기본</option>
      <option value="cursor">마우스 따라가기</option>
      <option value="hoverable">말풍선 위로 옮기기</option>
      <option value="keyboard">키보드 표시</option>
    </select>
  </div>
  <div id="grid" style="height: 240px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
example.js
const memos = ['오전 중 배송 요청', '선물 포장 필요', '', '세금계산서는 다음 달 초에 발행'];
const base = {
  columns: [
    { id: 'product', title: '상품', width: 140, headerTooltip: '주문한 상품 이름이에요.' },
    {
      id: 'price',
      title: '가격',
      kind: 'number',
      width: 110,
      align: 'end',
      // tooltipRenderer는 말풍선 안을 DOM으로 직접 채워요(HTML 문자열은 쓰지 않아요).
      tooltip: (row) => `${row.price}`,
      tooltipRenderer: (ctx, el) => {
        const strong = document.createElement('strong');
        strong.textContent = `${Number(ctx.text).toLocaleString()}원`;
        const small = document.createElement('small');
        small.textContent = ` (${ctx.rowKey}번 주문)`;
        el.append(strong, small);
      },
    },
    { id: 'memo', title: '메모', width: 220, tooltip: true },
  ],
  rows: memos.map((memo, i) => ({
    id: i + 1,
    product: ['이어폰', '노트북', '스마트워치', '보조배터리'][i],
    price: 59000 + i * 30000,
    memo,
  })),
  rowKey: 'id',
};
export const options = base;
// tooltipOptions는 위치(placement)·오프셋·마우스 따라가기·사라짐 지연·말풍선 위로 옮기기·키보드 표시(trigger)를 정해요.
const presets = {
  default: undefined,
  cursor: { placement: 'cursor', follow: true },
  hoverable: { hoverable: true, hideDelay: 300 },
  keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
  mode: (api, value) => api.setOptions({ tooltipOptions: presets[value ?? 'default'] }),
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<div id="app">
  <div class="toolbar">
    <select aria-label="Tooltip mode" id="mode">
      <option value="default" selected>Default</option>
      <option value="cursor">Follow pointer</option>
      <option value="hoverable">Hoverable tip</option>
      <option value="keyboard">Keyboard too</option>
    </select>
  </div>
  <div id="grid" style="height: 240px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
example.js
const memos = [
  'Deliver in the morning',
  'Gift wrapping needed',
  '',
  'Tax invoice early next month',
];
const base = {
  columns: [
    {
      id: 'product',
      title: 'Product',
      width: 140,
      headerTooltip: 'The name of the ordered product.',
    },
    {
      id: 'price',
      title: 'Price',
      kind: 'number',
      width: 110,
      align: 'end',
      // tooltipRenderer fills the tooltip directly with DOM nodes (no HTML strings).
      tooltip: (row) => `${row.price}`,
      tooltipRenderer: (ctx, el) => {
        const strong = document.createElement('strong');
        strong.textContent = `$${Number(ctx.text).toLocaleString('en-US')}`;
        const small = document.createElement('small');
        small.textContent = ` (order #${ctx.rowKey})`;
        el.append(strong, small);
      },
    },
    { id: 'memo', title: 'Memo', width: 220, tooltip: true },
  ],
  rows: memos.map((memo, i) => ({
    id: i + 1,
    product: ['Earbuds', 'Laptop', 'Smartwatch', 'Power Bank'][i],
    price: 59 + i * 30,
    memo,
  })),
  rowKey: 'id',
};
export const options = base;
// tooltipOptions sets the placement, offset, following the mouse, hide delay, moving onto the tooltip (hoverable) and keyboard display (trigger).
const presets = {
  default: undefined,
  cursor: { placement: 'cursor', follow: true },
  hoverable: { hoverable: true, hideDelay: 300 },
  keyboard: { trigger: 'both', placement: 'top' },
};
export const actions = {
  mode: (api, value) => api.setOptions({ tooltipOptions: presets[value ?? 'default'] }),
};