Show tooltip on disabled elements and disable tooltip in EJ2 TypeScript Tooltip control
8 May 20234 minutes to read
By default, tooltips will not be displayed on disabled elements. However, you can enable this behavior by using the following steps:
- Add a disabled element like the
button
element into a div whose display style is set toinline-block
. - Set the pointer event as
none
for the disabled element (button) through CSS. - Initialize the tooltip for outer div element that holds the disabled button element.
import { Tooltip } from '@syncfusion/ej2-popups';
import { Button, Switch } from '@syncfusion/ej2-buttons';
let tooltipObj_1: Tooltip = new Tooltip({
content: 'Tooltip from disabled element'
});
tooltipObj_1.appendTo('#box');
//Initialize Button component
let buttonObj_1: Button = new Button({
disabled: true
});
//Render initialized Button component
buttonObj_1.appendTo('#disabledbutton');
//Initialize Button component
let button: Button = new Button();
//Render initialized Button component
button.appendTo('#tooltip');
//Initialize Tooltip component
let tooltipObj_2: Tooltip = new Tooltip({
//Set tooltip content
content: 'Lets go green & Save Earth !!!'
});
//Render initialized Tooltip component
tooltipObj_2.appendTo('#tooltip');
let switchObj: Switch = new Switch({
value: 'USB tethering',
checked: true,
change: (args) => {
if ((document.getElementById('checked') as HTMLInputElement).checked) {
let tooltipObj_2: Tooltip = new Tooltip({
//Set tooltip content
content: "Lets go green & Save Earth !!!"
});
//Render initialized Tooltip component
tooltipObj_2.appendTo('#tooltip');
} else {
tooltipObj_2.destroy();
}
}
});
switchObj.appendTo('#checked');
<!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 id="box" style="display: inline-block;">
<input type="button" id="disabledbutton" value="Disabled button" />
</div>
<div style="position: relative;top: 75px;">
<!-- Tooltip element -->
<button id="tooltip">Show Tooltip</button>
<div class="switchContainer">
<label for="checked" style="padding: 0 25px 0 0">Enable Tooltip</label>
<input id="checked" type="checkbox" />
</div>
</div>
</div>
</body>
</html>