Setting dimension in EJ2 TypeScript Tooltip control
8 May 20235 minutes to read
Height and width
The Tooltip can either be assigned auto height and width values or specific pixel values. The width
and height
properties are used to
set the outer dimension of the Tooltip element. The default value for both the properties is auto
. It also accepts string and number values in pixels.
The following sample explains how to set dimensions for the Tooltip.
import { Tooltip } from '@syncfusion/ej2-popups';
import { Button } from '@syncfusion/ej2-buttons';
let tooltip: Tooltip = new Tooltip({
width: '180px',
height: '40px',
content: 'This tooltip has 180px width and 40px height'
});
tooltip.appendTo('#target');
let button: Button = new Button({
content: 'Show Tooltip'
});
button.appendTo('#target');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Tooltip</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container'>
<div style="display: inline-block; position: relative; left: 50%;top: 100px;transform: translateX(-50%);">
<span id='target'>Show Tooltip</span>
</div>
</div>
</body>
</html>
Scroll mode
When height
is specified with a certain pixel value and the Tooltip content overflows, the scrolling mode gets enabled.
import { Tooltip } from '@syncfusion/ej2-popups';
let tooltipContent: HTMLElement = document.createElement("div");
tooltipContent.id = 'tooltipContent';
tooltipContent.innerHTML = "<b>Environmentally friendly</b> or environment-friendly, (also referred to as eco-friendly, nature-friendly, and green) are marketing and sustainability terms referring to goods and services, laws, guidelines and policies that inflict reduced, minimal, or no harm upon ecosystems or the environment.";
let tooltip: Tooltip = new Tooltip({
width: '300px',
height: '60px',
content: tooltipContent,
isSticky: true
});
tooltip.appendTo('#target');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Tooltip</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container'>
<p>A green home is a type of house designed to be
<a id="target">
<u>environmentally friendly</u>
</a> and sustainable. And also focuses on the efficient use of "energy, water, and building materials." As green homes
have become more prevalent we have also seen the emergence of green affordable housing.
</p>
</div>
</body>
</html>
The scrolling mode can best be seen when the sticky mode of the Tooltip is enabled. To enable sticky mode, set the
isSticky
property to true.