Settings Button
The 💠component responsible for the Telegram Mini Apps settings button.
Checking Support
To check if the settings button supported by the current Telegram Mini Apps version, the isSupported
method is used:
ts
import { settingsButton } from '@telegram-apps/sdk';
settingsButton.isSupported(); // boolean
ts
import { isSettingsButtonSupported } from '@telegram-apps/sdk';
isSettingsButtonSupported(); // boolean
Mounting
Before using the component, it is necessary to mount it to work with properly configured properties. To do so, use the mount
method. It will update the isMounted
signal property.
ts
import { settingsButton } from '@telegram-apps/sdk';
settingsButton.mount();
settingsButton.isMounted(); // true
ts
import {
mountSettingsButton,
isSettingsButtonMounted,
} from '@telegram-apps/sdk';
mountSettingsButton();
isSettingsButtonMounted(); // true
To unmount, use the unmount
method:
ts
settingsButton.unmount();
settingsButton.isMounted(); // false
ts
import {
unmountSettingsButton,
isSettingsButtonMounted,
} from '@telegram-apps/sdk';
unmountSettingsButton();
isSettingsButtonMounted(); // false
Showing and Hiding
To change the button's visibility, use the hide()
and show()
methods. These methods update the isVisible
signal property value.
ts
settingsButton.show();
settingsButton.isVisible(); // true
settingsButton.hide();
settingsButton.isVisible(); // false
ts
import {
showSettingsButton,
hideSettingsButton,
isSettingsButtonVisible,
} from '@telegram-apps/sdk';
showSettingsButton();
isSettingsButtonVisible(); // true
hideSettingsButton();
isSettingsButtonVisible(); // false
Tracking Click
To add a button click listener, use the onClick
method. It returns a function to remove the bound listener. Alternatively, you can use the offClick
method.
ts
function listener() {
console.log('Clicked!');
}
const offClick = settingsButton.onClick(listener);
offClick();
// or
settingsButton.onClick(listener);
settingsButton.offClick(listener);
ts
import { onSettingsButtonClick, offSettingsButtonClick } from '@telegram-apps/sdk';
function listener() {
console.log('Clicked!');
}
const offClick = onSettingsButtonClick(listener);
offClick();
// or
onSettingsButtonClick(listener);
offSettingsButtonClick(listener);