# all files / src/widgets/ ButtonGroupWidget.js

70.59% Statements 12/17
37.5% Branches 3/8
33.33% Functions 1/3
70.59% Lines 12/17

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85

    1×

    24×

    24×

    24×

    24×
    24×
    18×

    1×
    1×

    1×

    1×

    1×

     /**
     * A ButtonGroupWidget groups related buttons and is used together with OO.ui.ButtonWidget and
     * its subclasses. Each button in a group is addressed by a unique reference. Buttons can be added,
     * removed, and cleared from the group.
     *
     *     @example
     *     // Example: A ButtonGroupWidget with two buttons
     *     var button1 = new OO.ui.PopupButtonWidget( {
     *         label: 'Select a category',
     *         icon: 'menu',
     *         popup: {
     *             $content: $( '<p>List of categories...</p>' ),
     *             padded: true,
     *             align: 'left'
     *         }
     *     } );
     *     var button2 = new OO.ui.ButtonWidget( {
     *         label: 'Add item'
     *     });
     *     var buttonGroup = new OO.ui.ButtonGroupWidget( {
     *         items: [button1, button2]
     *     } );
     *     $( 'body' ).append( buttonGroup.$element );
     *
     * @class
     * @extends OO.ui.Widget
     * @mixins OO.ui.mixin.GroupElement
     *
     * @constructor
     * @param {Object} [config] Configuration options
     * @cfg {OO.ui.ButtonWidget[]} [items] Buttons to add
     */
    OO.ui.ButtonGroupWidget = function OoUiButtonGroupWidget( config ) {
    	// Configuration initialization
    	config = config || {};

    	// Parent constructor
    	OO.ui.ButtonGroupWidget.parent.call( this, config );

    	// Mixin constructors
    	OO.ui.mixin.GroupElement.call( this, $.extend( {}, config, { $group: this.$element } ) );

    	// Initialization
    	this.$element.addClass( 'oo-ui-buttonGroupWidget' );
    	if ( Array.isArray( config.items ) ) {
    		this.addItems( config.items );
    	}
    };

    /* Setup */

    OO.inheritClass( OO.ui.ButtonGroupWidget, OO.ui.Widget );
    OO.mixinClass( OO.ui.ButtonGroupWidget, OO.ui.mixin.GroupElement );

    /* Static Properties */

    /**
     * @static
     * @inheritdoc
     */
    OO.ui.ButtonGroupWidget.static.tagName = 'span';

    /* Methods */

    /**
     * Focus the widget
     *
     * @chainable
     */
    OO.ui.ButtonGroupWidget.prototype.focus = function () {
    	if ( !this.isDisabled() ) {
    		if ( this.items[ 0 ] ) {
    			this.items[ 0 ].focus();
    		}
    	}
    	return this;
    };

    /**
     * @inheritdoc
     */
    OO.ui.ButtonGroupWidget.prototype.simulateLabelClick = function () {
    	this.focus();
    };