6 * Element with a button.
8 * Buttons are used for controls which can be clicked. They can be configured to use tab indexing
9 * and access keys for accessibility purposes.
20 protected $framed = false;
28 * @param array $config Configuration options
29 * @param bool $config['framed'] Render button with a frame (default: true)
31 public function initializeButtonElement( array $config = [] ) {
33 if ( ! $this instanceof Element ) {
34 throw new Exception( "ButtonElement trait can only be used on Element instances" );
36 $target = isset( $config['button'] ) ? $config['button'] : new Tag( 'a' );
37 $this->button = $target;
40 $this->addClasses( [ 'oo-ui-buttonElement' ] );
41 $this->button->addClasses( [ 'oo-ui-buttonElement-button' ] );
42 $this->toggleFramed( isset( $config['framed'] ) ? $config['framed'] : true );
44 // Add `role="button"` on `<a>` elements, where it's needed
45 if ( strtolower( $this->button->getTag() ) === 'a' ) {
46 $this->button->setAttributes( [
51 $this->registerConfigCallback( function ( &$config ) {
52 if ( $this->framed !== true ) {
53 $config['framed'] = $this->framed;
61 * @param bool $framed Make button framed, omit to toggle
64 public function toggleFramed( $framed = null ) {
65 $this->framed = $framed !== null ? !!$framed : !$this->framed;
66 $this->toggleClasses( [ 'oo-ui-buttonElement-framed' ], $this->framed );
67 $this->toggleClasses( [ 'oo-ui-buttonElement-frameless' ], !$this->framed );
72 * Check if button has a frame.
74 * @return bool Button is framed
76 public function isFramed() {