Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/205593
Change subject: ButtonWidget: Remove href to make unclickable when disabled
......................................................................
ButtonWidget: Remove href to make unclickable when disabled
Bug: T93004
Change-Id: Ib021392f85fea4f1df837b8e17f5c01fa114ba30
---
M php/widgets/ButtonWidget.php
M src/widgets/ButtonWidget.js
2 files changed, 45 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/93/205593/1
diff --git a/php/widgets/ButtonWidget.php b/php/widgets/ButtonWidget.php
index cf5750f..3e2679c 100644
--- a/php/widgets/ButtonWidget.php
+++ b/php/widgets/ButtonWidget.php
@@ -101,12 +101,23 @@
public function setHref( $href ) {
$this->href = is_string( $href ) ? $href : null;
- if ( $this->href !== null ) {
- $this->button->setAttributes( array( 'href' => $href )
);
+ $this->updateHref();
+
+ return $this;
+ }
+
+ /**
+ * Update the href attribute, in case of changes to href or disabled
+ * state.
+ *
+ * @chainable
+ */
+ public function updateHref() {
+ if ( $this->href !== null && !$this->isDisabled() ) {
+ $this->button->setAttributes( array( 'href' =>
$this->href ) );
} else {
$this->button->removeAttributes( array( 'href' ) );
}
-
return $this;
}
diff --git a/src/widgets/ButtonWidget.js b/src/widgets/ButtonWidget.js
index db04b5d..147e0ec 100644
--- a/src/widgets/ButtonWidget.js
+++ b/src/widgets/ButtonWidget.js
@@ -55,6 +55,9 @@
this.target = null;
this.noFollow = false;
+ // Events
+ this.connect( this, { disable: 'onDisable' } );
+
// Initialization
this.$button.append( this.$icon, this.$label, this.$indicator );
this.$element
@@ -161,17 +164,40 @@
if ( href !== this.href ) {
this.href = href;
- if ( href !== null ) {
- this.$button.attr( 'href', href );
- } else {
- this.$button.removeAttr( 'href' );
- }
+ this.updateHref();
}
return this;
};
/**
+ * Update the `href` attribute, in case of changes to href or
+ * disabled state.
+ *
+ * @private
+ * @chainable
+ */
+OO.ui.ButtonWidget.prototype.updateHref = function () {
+ if ( this.href !== null && !this.isDisabled() ) {
+ this.$button.attr( 'href', this.href );
+ } else {
+ this.$button.removeAttr( 'href' );
+ }
+
+ return this;
+};
+
+/**
+ * Handle disable events.
+ *
+ * @private
+ * @param {boolean} disabled Element is disabled
+ */
+OO.ui.ButtonWidget.prototype.onDisable = function () {
+ this.updateHref();
+};
+
+/**
* Set hyperlink target.
*
* @param {string|null} target Hyperlink target, null to remove
--
To view, visit https://gerrit.wikimedia.org/r/205593
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib021392f85fea4f1df837b8e17f5c01fa114ba30
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits