Size modes Size Mode for Syncfusion EJ2 TypeScript Controls

10 May 20239 minutes to read

An application that is designed to be accessed through a web browser on various devices, including desktop computers and mobile devices, may have a distinct layout or user interface on a mobile device compared to a desktop computer to better suit the smaller screen size.

Syncfusion JavaScript controls support both touch (bigger) and normal size modes. Touch mode creates a responsive design for mobile devices by adding the e-bigger class, which enhances interactions, visibility, and the overall experience.

Size mode for application

The user can enable touch mode (bigger) for the entire application by adding the e-bigger class to the body element in the index.html file as follows:

  <body className="e-bigger">
    ...
  </body>

Size mode for a control

The user can enable touch mode (bigger) for a control by adding the e-bigger class to the div element that contains the control. Another way of enabling touch mode is by adding the e-bigger class using the available cssClass property of the control.

import { Button } from '@syncfusion/ej2-buttons';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

// Initialize the Button component.
let button: Button = new Button({ content: 'Button' });

// Render initialized button.
button.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</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/25.1.35/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/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='container' class="e-bigger">
        <div id='loader'>Loading....</div>
        <button id="element">Button</button>
    </div>
</body>

</html>

Change size mode for application at runtime

The user can change the size mode of the application between touch and normal (mouse) mode at runtime by adding and removing the e-bigger class. The following steps explain how to change the size mode of an application at runtime:

import { Button } from '@syncfusion/ej2-buttons';
import { enableRipple } from '@syncfusion/ej2-base';
import { Calendar } from '@syncfusion/ej2-calendars';

enableRipple(true);

// Initialize the touch button.
let touchButton: Button = new Button({ content: 'Touch Mode' });
touchButton.appendTo('#touch');
touchButton.element.onclick = (): void => {
    document.body.classList.add('e-bigger');
}
// Initialize the mouse button.
let mouseButton: Button = new Button({ content: 'Mouse Mode' });
mouseButton.appendTo('#mouse');
mouseButton.element.onclick = (): void => {
    document.body.classList.remove('e-bigger');
}
let calendarObject: Calendar = new Calendar();
//Render initialized calendar.
calendarObject.appendTo('#calendar');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</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/25.1.35/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-buttons/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-calendars/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>
            <button id="touch"></button>
            <button id="mouse"></button>
        </div>
        <div class="control">
            <div id='calendar'></div>
        </div>
    </div>
</body>

</html>

Change size mode for a control at runtime

The user can change the size mode of a control between touch and normal (mouse) mode at runtime by setting the e-bigger CSS class.

import { Button } from '@syncfusion/ej2-buttons';
import { enableRipple } from '@syncfusion/ej2-base';
import { Calendar } from '@syncfusion/ej2-calendars';

enableRipple(true);

// Initialize the touch button.
let touchButton: Button = new Button({ content: 'Touch Mode' });
touchButton.appendTo('#touch');
touchButton.element.onclick = (): void => {
    let controls = document.querySelectorAll('.control');
        for (let index: number = 0; index < controls.length; index++) {
            controls[index].classList.add('e-bigger');
        }
}
// Initialize the mouse button.
let mouseButton: Button = new Button({ content: 'Mouse Mode' });
mouseButton.appendTo('#mouse');
mouseButton.element.onclick = (): void => {
    let controls = document.querySelectorAll('.control');
        for (let index: number = 0; index < controls.length; index++) {
            controls[index].classList.remove('e-bigger');
        }
}
let calendarObject: Calendar = new Calendar();
//Render initialized calendar.
calendarObject.appendTo('#calendar');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</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/25.1.35/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-buttons/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-calendars/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>
            <button id="touch"></button>
            <button id="mouse"></button>
        </div>
        <div class="control">
            <div id='calendar'></div>
        </div>
    </div>
</body>

</html>

See also