v7.3.0

Button
Widget

Button widget, wraps and styles a regular <button> element. Can display text and icon and also allows specifying button color. Supports different appearances, by setting rendition to one of:

  • 'text' - Flat appearance with text only, no background or border
  • 'outlined' - Transparent button with border
  • 'tonal' - Flat appearance with "soft" background color
  • 'filled' - Flat appearance with stronger background color
  • 'elevated' - Raised appearance

// Green button with text and icon
const button = new Button({
    appendTo : document.body,
    icon    : 'fa fa-plus-circle',
    text    : 'Add',
    color   : 'b-green',
    onClick : () => {}
});

Button with menu

Buttons can also have a menu that is shown on click, or on click or hover of only the menu icon part of the button (if split is set):

const button = new Button({
    appendTo : document.body,
    icon    : 'fa fa-chart',
    menu    : {
        items : [
            {
                text : 'Click me',
                onItem : () => console.log('I was clicked')
            }
        ]
    }
});

Click handling in a complex widget

In the case of a button which is part of a complex UI within a larger Bryntum widget, use of the string form for handlers is advised. A handler which starts with 'up.' will be resolved by looking in owning widgets of the Button. For example a Calendar may have handlers for its buttons configured in:

new Calendar({
    appendTo : document.body,
    project  : myProjectConfig,
    sidebar  : {
        items : {
            addNew : {
                weight  : 0,
                text    : 'New',

// The Button's ownership will be traversed to find this function name. // It will be called on the outermost Calendar widget. onClick : 'up.onAddNewClick' } } },

// Button handler found here onAddNewClick() { // Use Calendar API which creates event in the currently active date this.createEvent(); } });

This class may be operated by the keyboard. Space presses the button and invokes any click handler, and ArrowDown activates any configured menu.

No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • behaviorType : 'button'/'submit'/'reset'button

    The button behavioral type, will be applied as a type attribute to this button's element.

    Has a corresponding runtime behaviorType property.

  • If provided, turns the button into a link.

    Not compatible with the adopt config.

    Has a corresponding runtime href property.

  • iconAlign : 'start'/'end'start

    Button icon alignment. May be 'start' or 'end'. Defaults to 'start'

    Has a corresponding runtime iconAlign property.

  • A CSS class to add to the pressed state of the button. A b-pressed CSS class is always added, when a button is pressed.

    Has a corresponding runtime pressedCls property.

  • Set to true to perform action on clicking the button if it's already pressed and belongs to a toggleGroup.

  • The target attribute for the href config

    Has a corresponding runtime target property.

  • The button's text. You can also supply a DomConfig or an array of DomConfigs for complex button content.

    Has a corresponding runtime text property.

  • Enabled toggling of the button (stays pressed when pressed).

    Has a corresponding runtime toggleable property.

Properties

Properties are getters/setters or publicly accessible variables on this class
  • isButton : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of Button class, or subclass thereof.
  • behaviorType : 'button'/'submit'/'reset'button

    The button behavioral type, will be applied as a type attribute to this button's element.

    Has a corresponding behaviorType config.

  • If provided, turns the button into a link.

    Not compatible with the adopt config.

    Has a corresponding href config.

  • iconAlign : 'start'/'end'start

    Button icon alignment. May be 'start' or 'end'. Defaults to 'start'

    Has a corresponding iconAlign config.

  • Returns the instantiated menu widget as configured by menu.

    Has a corresponding menu config.

  • A CSS class to add to the pressed state of the button. A b-pressed CSS class is always added, when a button is pressed.

    Has a corresponding pressedCls config.

  • The target attribute for the href config

    Has a corresponding target config.

  • The button's text. You can also supply a DomConfig or an array of DomConfigs for complex button content.

    Has a corresponding text config.

  • Enabled toggling of the button (stays pressed when pressed).

    Has a corresponding toggleable config.

  • isButton : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of Button class, or subclass thereof.

Functions

Functions are methods available for calling on the class
    • onInternalClick( )
      internal

      Triggers events when user clicks button


      Triggers: click, action

    Events

    Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

    Event handlers

    Event handlers are callbacks called as a result of certain actions in this class

    CSS variables

    CSS variables that can be set to adjust appearance
    Name Description
    --b-button-border-radius Button border-radius
    --b-button-box-shadow Button box-shadow, overridden by renditions
    --b-button-elevated-background
    elevated
    Background for elevated buttons
    --b-button-elevated-box-shadow
    elevated
    Box-shadow for elevated buttons
    --b-button-elevated-color
    elevated
    Text color for elevated buttons
    --b-button-elevated-color
    elevated
    Text color for elevated buttons
    --b-button-end-icon-padding-inline Inline padding for buttons with icon at the end
    --b-button-filled-background
    filled
    Background for filled buttons
    --b-button-filled-color
    filled
    Text color for filled buttons
    --b-button-font-weight Button text font-weight
    --b-button-gap Gap between icon and label
    --b-button-height Button height
    --b-button-icon-only-border-radius Border-radius for icon-only buttons
    --b-button-icon-padding-inline Inline padding for buttons with icon
    --b-button-menu-padding-inline Inline padding for buttons with menu
    --b-button-opacity Button opacity
    --b-button-outlined-background
    outlined
    Background for outlined buttons
    --b-button-outlined-border-color
    outlined
    Border color for outlined buttons
    --b-button-outlined-border-width
    outlined
    Border width for outlined buttons
    --b-button-outlined-color
    outlined
    Text color for outlined buttons
    --b-button-outlined-hover-border-color
    outlined
    Border color for hovered outlined buttons
    --b-button-padding-inline Text-only button inline padding
    --b-button-text-align Button text-align
    --b-button-tonal-background
    tonal
    Background for tonal buttons
    --b-button-tonal-border-color
    tonal
    Border color for tonal buttons
    --b-button-tonal-border-width
    tonal
    Border width for tonal buttons
    --b-button-tonal-color
    tonal
    Text color for tonal buttons
    --b-button-type-text-background
    text
    Background for text buttons
    --b-button-type-text-color
    text
    Text color for text buttons
    Active
    --b-button-active-box-shadow Box-shadow for active buttons, overridden by renditions
    --b-button-elevated-active-background
    elevated
    Background for active elevated buttons
    --b-button-elevated-active-box-shadow
    elevated
    Box-shadow for active elevated buttons
    --b-button-filled-active-background
    filled
    Background for active filled buttons
    --b-button-outlined-active-background
    outlined
    Background for active outlined buttons
    --b-button-tonal-active-background
    tonal
    Background for active tonal buttons
    --b-button-type-text-active-background
    text
    Background for active text buttons
    Disabled
    --b-button-disabled-background Background for disabled buttons
    --b-button-disabled-border-color Border-color for disabled buttons
    --b-button-disabled-color Disabled button text color
    --b-button-disabled-opacity Opacity for disabled buttons
    --b-button-outlined-disabled-background
    outlined
    Background for disabled outlined buttons
    --b-button-outlined-disabled-border-color
    outlined
    Border color for disabled outlined buttons
    --b-button-type-text-disabled-background
    text
    Background for disabled text buttons
    Focused
    --b-button-elevated-focus-box-shadow
    elevated
    Box-shadow for focused elevated buttons
    --b-button-elevated-focused-background
    elevated
    Background for focused elevated buttons
    --b-button-filled-focused-background
    filled
    Background for focused filled buttons
    --b-button-focus-border-color Border-color for focused buttons, overridden by renditions
    --b-button-focus-box-shadow Box-shadow for focused buttons, overridden by renditions
    --b-button-focus-outline-color Focus outline color
    --b-button-focus-outline-offset Focus outline offset
    --b-button-focus-outline-width Focus outline width
    --b-button-outlined-focus-border-color
    outlined
    Border color for focused outlined buttons
    --b-button-outlined-focus-border-color
    outlined
    Border color for focused outlined buttons
    --b-button-outlined-focused-background
    outlined
    Background for focused outlined buttons
    --b-button-tonal-focused-background
    tonal
    Background for focused tonal buttons
    --b-button-type-text-focused-background Background for focused text buttons
    Hovered
    --b-button-elevated-hover-background
    elevated
    Background for hovered elevated buttons
    --b-button-elevated-hover-box-shadow
    elevated
    Box-shadow for hovered elevated buttons
    --b-button-filled-hover-background
    filled
    Background for hovered filled buttons
    --b-button-filled-hover-box-shadow
    filled
    Box-shadow for hovered filled buttons
    --b-button-hover-box-shadow Box-shadow for hovered buttons, overridden by renditions
    --b-button-outlined-hover-background
    outlined
    Background for hovered outlined buttons
    --b-button-tonal-hover-background
    tonal
    Background for hovered tonal buttons
    --b-button-tonal-hover-box-shadow
    tonal
    Box-shadow for hovered tonal buttons
    --b-button-type-text-hover-background
    text
    Background for hovered text buttons
    Pressed
    --b-button-elevated-pressed-background
    elevated
    Background for pressed elevated buttons
    --b-button-elevated-pressed-hover-background
    elevated
    Background for hovered pressed elevated buttons
    --b-button-filled-pressed-background
    filled
    Background for pressed filled buttons
    --b-button-filled-pressed-hover-background
    filled
    Background for hovered pressed filled buttons
    --b-button-outlined-pressed-background
    outlined
    Background for pressed outlined buttons
    --b-button-outlined-pressed-color
    outlined
    Text color for pressed outlined buttons
    --b-button-outlined-pressed-hover-background
    outlined
    Background for hovered pressed outlined buttons
    --b-button-pressed-box-shadow Box-shadow for pressed buttons, overridden by renditions
    --b-button-tonal-pressed-background
    tonal
    Background for pressed tonal buttons
    --b-button-tonal-pressed-hover-background
    tonal
    Background for hovered pressed tonal buttons
    --b-button-type-text-pressed-background
    text
    Background for pressed text buttons
    --b-button-type-text-pressed-hover-background
    text
    Background for hovered pressed text buttons
    type: button

    Source path

    Core/widget/Button.js

    Contents