Bartosz Dziewoński has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/360903 )
Change subject: FieldLayout: Show widget's accesskey in our title
......................................................................
FieldLayout: Show widget's accesskey in our title
I don't like this at all, but I don't see a better way.
Bug: T168408
Change-Id: Ie36cd9133e35163c124edf745aaa876c47e3f968
---
M demos/pages/widgets.js
M demos/pages/widgets.php
M php/layouts/FieldLayout.php
M php/mixins/AccessKeyedElement.php
M src/layouts/FieldLayout.js
M src/mixins/AccessKeyedElement.js
6 files changed, 58 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/03/360903/1
diff --git a/demos/pages/widgets.js b/demos/pages/widgets.js
index 598e85f..28e73f6 100644
--- a/demos/pages/widgets.js
+++ b/demos/pages/widgets.js
@@ -938,6 +938,17 @@
}
),
new OO.ui.FieldLayout(
+ new OO.ui.CheckboxInputWidget( {
+ selected: true,
+ accessKey: 't'
+ } ),
+ {
+ align: 'inline',
+ label: 'CheckboxInputWidget
(with accesskey T and title)\u200E',
+ title: 'Access key is added to
the title.'
+ }
+ ),
+ new OO.ui.FieldLayout(
new OO.ui.RadioInputWidget( {
name: 'oojs-ui-radio-demo'
} ),
diff --git a/demos/pages/widgets.php b/demos/pages/widgets.php
index 63c237b..7467aed 100644
--- a/demos/pages/widgets.php
+++ b/demos/pages/widgets.php
@@ -527,6 +527,17 @@
]
),
new OOUI\FieldLayout(
+ new OOUI\CheckboxInputWidget( [
+ 'selected' => true,
+ 'accessKey' => 't'
+ ] ),
+ [
+ 'align' => 'inline',
+ 'label' => "CheckboxInputWidget (with accesskey
T and title)\xE2\x80\x8E",
+ 'title' => 'Access key is added to the title.',
+ ]
+ ),
+ new OOUI\FieldLayout(
new OOUI\RadioInputWidget( [
'name' => 'oojs-ui-radio-demo'
] ),
diff --git a/php/layouts/FieldLayout.php b/php/layouts/FieldLayout.php
index 78aab90..8863307 100644
--- a/php/layouts/FieldLayout.php
+++ b/php/layouts/FieldLayout.php
@@ -135,6 +135,8 @@
}
$this->setAlignment( $config['align'] );
+ // Call this again to take into account the widget's accessKey
+ $this->updateTitle();
}
/**
@@ -222,6 +224,20 @@
return $this;
}
+ /**
+ * Include information about the widget's accessKey in our title.
TitledElement calls this method.
+ * (This is a bit of a hack.)
+ *
+ * @param string $title
+ * @return string
+ */
+ protected function formatTitleWithAccessKey( $title ) {
+ if ( $this->fieldWidget && method_exists( $this->fieldWidget,
'formatTitleWithAccessKey' ) ) {
+ return $this->fieldWidget->formatTitleWithAccessKey(
$title );
+ }
+ return $title;
+ }
+
public function getConfig( &$config ) {
$config['fieldWidget'] = $this->fieldWidget;
$config['align'] = $this->align;
diff --git a/php/mixins/AccessKeyedElement.php
b/php/mixins/AccessKeyedElement.php
index 5108ce2..70261a7 100644
--- a/php/mixins/AccessKeyedElement.php
+++ b/php/mixins/AccessKeyedElement.php
@@ -81,11 +81,12 @@
/**
* Add information about the access key to the element's tooltip label.
+ * (This is only public for hacky usage in FieldLayout.)
*
* @param string $title
* @return string
*/
- protected function formatTitleWithAccessKey( $title ) {
+ public function formatTitleWithAccessKey( $title ) {
$accessKey = $this->getAccessKey();
if ( $accessKey ) {
$title .= " [$accessKey]";
diff --git a/src/layouts/FieldLayout.js b/src/layouts/FieldLayout.js
index 2bbe48a..c0e6a2c 100644
--- a/src/layouts/FieldLayout.js
+++ b/src/layouts/FieldLayout.js
@@ -119,6 +119,8 @@
this.setErrors( config.errors || [] );
this.setNotices( config.notices || [] );
this.setAlignment( config.align );
+ // Call this again to take into account the widget's accessKey
+ this.updateTitle();
};
/* Setup */
@@ -274,3 +276,18 @@
this.$messages.append( this.makeMessage( 'error', this.errors[
i ] ) );
}
};
+
+/**
+ * Include information about the widget's accessKey in our title.
TitledElement calls this method.
+ * (This is a bit of a hack.)
+ *
+ * @protected
+ * @param {string} title
+ * @return {string}
+ */
+OO.ui.FieldLayout.prototype.formatTitleWithAccessKey = function ( title ) {
+ if ( this.fieldWidget && this.fieldWidget.formatTitleWithAccessKey ) {
+ return this.fieldWidget.formatTitleWithAccessKey( title );
+ }
+ return title;
+};
diff --git a/src/mixins/AccessKeyedElement.js b/src/mixins/AccessKeyedElement.js
index 41181b2..c0ee5d2 100644
--- a/src/mixins/AccessKeyedElement.js
+++ b/src/mixins/AccessKeyedElement.js
@@ -112,8 +112,8 @@
/**
* Add information about the access key to the element's tooltip label.
+ * (This is only public for hacky usage in FieldLayout.)
*
- * @protected
* @param {string} title
* @return {string}
*/
--
To view, visit https://gerrit.wikimedia.org/r/360903
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie36cd9133e35163c124edf745aaa876c47e3f968
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