Ignite UI for Web Components Tooltip 구성 요소는 특정 요소에 대한 도구 설명을 표시하는 방법을 제공합니다. 툴팁은 요소와 관련된 정보를 표시하는 팝업으로, 일반적으로 요소가 키보드 포커스를 받거나 마우스가 그 위로 마우스를 가져갈 때 표시됩니다.
<!DOCTYPE html><html><head><title>Tooltip Overview</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-avatarid="avatar"src="https://www.infragistics.com/angular-demos-lob/assets/images/avatar/10.jpg"shape="circle"></igc-avatar><igc-tooltipanchor="avatar">Her name is Madelyn James</igc-tooltip></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html
Now you can start with a basic configuration of the Web Components IgcTooltipComponent.
<igc-tooltipanchor="hover-button">
Congrats you've hovered the button!
</igc-tooltip><igc-buttonid="hover-button">Hover me</igc-button>html
Ignite UI for Web Components에 대한 전체 소개를 보려면 시작하기 항목을 읽어보세요.
Usage
Tooltip target
To attach a tooltip to the desired element, use the anchor property on the <igc-tooltip> element. This property accepts either an element ID or a direct reference to an element. When using an ID reference, simply set the anchor property to the ID of the target element.
<igc-buttonid="target-button">Hover me</igc-button><igc-tooltipanchor="target-button">
Congrats you've hovered the button!
</igc-tooltip>html
element 인스턴스를 직접 전달하여 대상을 지정할 수도 있습니다.
<igc-tooltipid="tooltip">
Congrats you've hovered the button!
</igc-tooltip><igc-buttonid="hover-button">Hover me</igc-button>html
constructor() {
const anchor = document.querySelector('#hover-button') as IgcButtonComponent;
const tooltip = document.querySelector('#tooltip') as IgcTooltipComponent;
tooltip.anchor = anchor;
}
ts
Tooltip content
The Tooltip content is defined by placing custom content between the opening and closing tags of the <igc-tooltip> element.
<igc-tooltip>
This is my custom content here.
</igc-tooltip>html
<igc-tooltipmessage="This is my custom content here."></igc-tooltip>html
두 가지 접근 방식(슬롯된 콘텐츠와 속성) message을 모두 사용하는 경우 슬롯된 콘텐츠가 우선적으로 적용되고 message 값은 무시됩니다.
<igc-buttonid="target-button">Hover me</igc-button><igc-tooltipanchor="target-button"message="I will be hidden.">
I will be shown!
</igc-tooltip>html
이 예제에서는 속성 값 대신 message 슬롯이 있는 콘텐츠("I will be shown!")가 표시됩니다.
The IgcTooltipComponent content can be more than just simple text. Since the IgcTooltipComponent is a regular element in the markup, you can enhance its content by adding any elements you need and styling them accordingly.
<!DOCTYPE html><html><head><title>Rich Tooltip</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><divclass="map"><igc-iconid="location_icon"slot="actions"variant="flat"collection="material"exportparts="icon"name="location_on"></igc-icon><igc-tooltipanchor="location_icon"class="locationTooltip"><divclass="locationTooltipContent"><igc-avatarclass="logo"src="https://www.infragistics.com/angular-demos-lob/assets/images/card/avatars/igLogo.png"size="medium"shape="square"></igc-avatar><div><div>Infragistics Inc. HQ</div><div>2 Commerce Dr, Cranbury, NJ 08512, USA</div></div></div></igc-tooltip></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html
If you want to control the delay before showing and hiding the IgcTooltipComponent, you can use the showDelay and hideDelay properties. Both properties accept a number value representing time in milliseconds.
<igc-tooltipshow-delay="600"hide-delay="800">
Her name is Madelyn James.
</igc-tooltip>html
It's important to note that the Tooltip API methods — show, hide, and toggle — DO NOT take the showDelay and hideDelay properties into account. They act immediately when invoked.
Placement
The IgcTooltipComponent can also be positioned relative to its target element with ease. All you need to do is use the placement property along with one of the following position options: top, top-start, top-end, bottom, bottom-start, bottom-end , right, right-start, right-end, left, left-start, left-end.
If the placement property is not set, the default value is "top", which places the IgcTooltipComponent above the target element.
Additionally, you can make the IgcTooltipComponent "sticky" using the sticky property, which adds a close button and keeps the IgcTooltipComponent visible until the user closes it manually - either by clicking the close button or pressing the Esc key. This behavior overrides the default hover behavior, preventing the IgcTooltipComponent from disappearing when the user stops hovering over the target element.
<igc-buttonid="target-button">Hover me</igc-button><igc-tooltipanchor="target-button"placement="top-start"sticky>
Congrats you've hovered the button!
</igc-tooltip>html
<!DOCTYPE html><html><head><title>Tooltip Placement</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><divid="btnWrapper"></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html
By default, the IgcTooltipComponent is triggered only while hovering over the target element. However, you can change this behavior using the showTriggers and hideTriggers properties, which allow you to control when the IgcTooltipComponent appears and disappears. These properties accept event names as values—such as click, focus, or keypress—letting you trigger the IgcTooltipComponent in different scenarios.
<!DOCTYPE html><html><head><title>Tooltip Triggers</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><divid="triggers-container"><igc-card><igc-card-header><h4slot="title">Default triggers</h4></igc-card-header><igc-card-content><p>
Hovering over the button below will display the tooltip using its default configuration: it appears on <strong>pointer enter</strong> and hides on <strong>pointer leave</strong> or <strong>click</strong>.
</p><igc-buttonvariant="outlined"id="triggers-default">Hover over me</igc-button><igc-tooltipanchor="triggers-default">
I am show on pointer enter and hidden on pointer leave and/or click.
</igc-tooltip></igc-card-content></igc-card><igc-card><igc-card-header><h4slot="title">Focus based</h4></igc-card-header><igc-card-content><p>
In this instance, the tooltip is bound to show on its anchor
<strong>focus</strong> and will hide when its anchor is
<strong>blurred</strong>.
</p><p>Try to navigate with a Tab key to the anchor to see the effect.</p><igc-buttonvariant="outlined"id="triggers-focus-blur">Focus me</igc-button><igc-tooltipanchor="triggers-focus-blur"show-delay="0"hide-delay="0"show-triggers="focus"hide-triggers="blur">
I am shown on focus and hidden on blur.
</igc-tooltip></igc-card-content></igc-card><igc-card><igc-card-header><h4slot="title">Same trigger(s) for showing and hiding</h4></igc-card-header><igc-card-content><p>
The same trigger can be bound to both show and hide the tooltip. The
button below has its tooltip bound to show/hide on
<strong>click</strong>.
</p><igc-buttonvariant="outlined"id="triggers-click">Click</igc-button><igc-tooltipshow-delay="0"hide-delay="0"anchor="triggers-click"show-triggers="click"hide-triggers="click">
I am show on click and will hide on anchor click.
</igc-tooltip></igc-card-content></igc-card><igc-card><igc-card-header><h4slot="title">Keyboard interactions</h4></igc-card-header><igc-card-content><p>
Keyboard interactions are also supported. The button below has its
tooltip bound to show on a <strong>keypress</strong> and hide on a
<strong>keypress</strong> or <strong>blur</strong>.
</p><p>Try it out by focusing the button and pressing a key.</p><igc-buttonvariant="outlined"id="triggers-keypress">Press a key</igc-button><igc-tooltipanchor="triggers-keypress"show-triggers="keypress"hide-triggers="keypress blur">
I am shown on a keypress and will hide on a keypress or blur.
</igc-tooltip></igc-card-content></igc-card><igc-card><igc-card-header><h4slot="title">Custom events</h4></igc-card-header><igc-card-content><p>
The tooltip supports any DOM event, including custom events. Try entering a value in the input below, then "commit" it by either <strong>blurring</strong> the input or pressing <strong>Enter</strong>.
</p><igc-inputvariant="outlined"id="triggers-custom"label="Username"></igc-input><igc-tooltipanchor="triggers-custom"show-triggers="igcChange">
Value changed!
</igc-tooltip></igc-card-content></igc-card></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html
Apart from the properties we've already covered, the IgcTooltipComponent component offers a variety of additional properties that allow you to further configure its behavior, position, and appearance.
<!DOCTYPE html><html><head><title>Tooltip Styling</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-avatarid="avatar"src="https://www.infragistics.com/angular-demos-lob/assets/images/avatar/10.jpg"shape="circle"></igc-avatar><igc-tooltipid="tool1"anchor="avatar">Her name is Madelyn James</igc-tooltip></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css