This is the more native way of doing things, which avoids syncing different states between the toggle and the hidden widget. The DOM structure is also better and don't confuse screen readers. Bug: T333496 Bug: T334705 Bug: T336107 Change-Id: I47de69459b96f172153065094eb4113584bb435a
25 lines
573 B
PHP
25 lines
573 B
PHP
<?php
|
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
use OOUI\CheckboxInputWidget;
|
|
|
|
/**
|
|
* Base class for widgets to warp a checkbox into toggle widget.
|
|
*
|
|
* @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
|
|
* @license MIT
|
|
*/
|
|
class ToggleSwitchWidget extends CheckboxInputWidget {
|
|
|
|
public function __construct( array $config = [] ) {
|
|
parent::__construct( $config );
|
|
|
|
$this->setValue( $config['selected'] );
|
|
$this->addClasses( [ 'mw-widgets-toggleSwitchWidget' ] );
|
|
}
|
|
|
|
protected function getJavaScriptClassName() {
|
|
return 'mw.widgets.ToggleSwitchWidget';
|
|
}
|
|
}
|