Skip to main content

Button

The Button component is an interactive element activated by the user. Once activated, it performs an action, such as submitting a form or opening a dialog.

Usage​

Buttons can display text, icons, or both. They can be colored and styled with various options.

All the options can be passed to the button via data- attributes with exceptions of the native button supported ones. The attributes that the native html button supports can be passed directly without the data- prefix. For example the disabled attribute.

Button styles​

Button variations
<button mbsc-button>Standard button</button>
<button mbsc-button data-variant="flat">Flat button</button>
<button mbsc-button data-variant="outline">Outline button</button>

<button mbsc-button data-start-icon="home">With start icon</button>
<button mbsc-button data-end-icon="home">With end icon</button>
<button mbsc-button data-icon="pencil" data-aria-label="Icon only"></button>

<button mbsc-button data-color="primary">Primary button</button>
<button mbsc-button data-color="secondary">Secondary button</button>
<button mbsc-button data-color="success">Success button</button>
<button mbsc-button data-color="danger">Danger button</button>
<button mbsc-button data-color="warning">Warning button</button>
<button mbsc-button data-color="info">Info button</button>
<button mbsc-button data-color="light">Light button</button>
<button mbsc-button data-color="dark">Dark button</button>

Button sizes and groups​

<!-- Full width button -->
<button mbsc-button class="mbsc-button-block">Full width Button</button>

<!-- Button group -->
<div class="mbsc-button-group">
<button mbsc-button>Button 1</button>
<button mbsc-button>Button 2</button>
<button mbsc-button>Button 3</button>
</div>

<!-- Justified group -->
<!-- Buttons are streched to fill the full width of the container -->
<div class="mbsc-button-group-justified">
<button mbsc-button>Button 1</button>
<button mbsc-button>Button 2</button>
<button mbsc-button>Button 3</button>
</div>

<!-- Full width group -->
<!-- Each button fills the whole width of the container -->
<div class="mbsc-button-group-block">
<button mbsc-button>Button 1</button>
<button mbsc-button>Button 2</button>
<button mbsc-button>Button 3</button>
</div>

Auto vs. manual initialization​

If the component is added later to the DOM, e.g. with an AJAX page load, a custom function named enhance needs to be called in order to initialize the dynamically added component. When the enhance function is called on a DOM element, all form elements will be initialized inside this element.

$.get('/myform', function (responseHtml) {
var $page = $('#page');
$page.html(responseHtml);
mobiscroll.enhance($page[0]);
});

Options​

Explore the following API options that help you easily configure the Button component.

ariaLabel​

string

Specifies the accessible name of the button. Recommended for icon-only buttons.

Default value: undefined

color​

"success" | "light" | "dark" | "primary" | "secondary" | "danger" | "warning" | "info"

Specifies the predefined color of the button.

Default value: undefined

cssClass​

string

Specifies a custom CSS class for the component.

Default value: undefined

disabled​

boolean

Specifies the disabled state of the button.

Default value: false

endIcon​

any

Specifies the icon which will be displayed at the end of the button. Use the startIcon option for specifying an icon at the start.

Default value: undefined

icon​

any

Specifies the icon for an icon-only button.

Default value: undefined

startIcon​

any

Specifies the icon which will be displayed at the start of the button. Use the endIcon option for specifying an icon at the end.

Default value: undefined

tabIndex​

number

Specifies the tabindex attribute of the button.

Default value: undefined

theme​

string

Specifies the visual appearance of the component.

If it is 'auto' or undefined, the theme will automatically be chosen based on the platform. If custom themes are also present, they will take precedence over the built in themes, e.g. if there's an iOS based custom theme, it will be chosen on the iOS platform instead of the default iOS theme.

Supplied themes:

  • 'ios' - iOS theme
  • 'material' - Material theme
  • 'windows' - Windows theme

It's possible to modify theme colors or create custom themes.

info

Make sure that the theme you set is included in the downloaded package.

Default value: undefined

themeVariant​

"auto" | "light" | "dark"

Controls which variant of the theme will be used (light or dark).

Possible values:

  • 'light' - Use the light variant of the theme.
  • 'dark' - Use the dark variant of the theme.
  • 'auto' or undefined - Detect the preferred system theme on devices where this is supported.

To use the option with custom themes, make sure to create two custom themes, where the dark version has the same name as the light one, suffixed with '-dark', e.g.: 'my-theme' and 'my-theme-dark'.

Default value: undefined

variant​

"outline" | "standard" | "flat"

Specifies the style of the button.

Default value: 'standard'

Localization​

The Button component is fully localized. This covers date and time format, button copy, rtl and more.

locale​

MbscLocale

Sets the language of the component. The locale object contains all the translations for a given language. The built in language modules are listed below. If a language is not listed, it can be provided as a custom language module.

Supported values:

  • Arabic: localeAr, 'ar'
  • Bulgarian: localeBg, 'bg'
  • Catalan: localeCa, 'ca'
  • Czech: localeCs, 'cs'
  • Chinese: localeZh, 'zh'
  • Croatian: localeHr, 'hr'
  • Danish: localeDa, 'da'
  • Dutch: localeNl, 'nl'
  • English: localeEn or undefined, 'en'
  • English (UK): localeEnGB, 'en-GB'
  • Farsi: localeFa, 'fa'
  • German: localeDe, 'de'
  • Greek: localeEl, 'el'
  • Spanish: localeEs, 'es'
  • Finnish: localeFi, 'fi'
  • French: localeFr, 'fr'
  • Hebrew: localeHe, 'he'
  • Hindi: localeHi, 'hi'
  • Hungarian: localeHu, 'hu'
  • Italian: localeIt, 'it'
  • Japanese: localeJa, 'ja'
  • Korean: localeKo, 'ko'
  • Lithuanian: localeLt, 'lt'
  • Norwegian: localeNo, 'no'
  • Polish: localePl, 'pl'
  • Portuguese (Brazilian): localePtBR, 'pt-BR'
  • Portuguese (European): localePtPT, 'pt-PT'
  • Romanian: localeRo, 'ro'
  • Russian: localeRu, 'ru'
  • Russian (UA): localeRuUA, 'ru-UA'
  • Slovak: localeSk, 'sk'
  • Serbian: localeSr, 'sr'
  • Swedish: localeSv, 'sv'
  • Thai: localeTh, 'th'
  • Turkish: localeTr, 'tr'
  • Ukrainian: localeUa, 'ua'

Default value: undefined

rtl​

boolean

Enables right-to-left display.

Default value: false

Events​

The Button component ships with different event hooks for deep customization. Events are triggered through the lifecycle of the component where you can tie in custom functionality and code.

onDestroy​

(args: any, inst: any) => void

Triggered when the component is destroyed.

Parameters:

  • args - The event argument object.

  • inst - The component instance.

onInit​

(args: any, inst: any) => void

Triggered when the component is initialized.

Parameters:

  • args - The event argument object.

  • inst - The component instance.