Skip to content

A platform for community discussion. Free, open, simple.

UX: Don't default title to label text for buttons.

Guo Xiang Tan08d68e846c48
diff --git a/app/assets/javascripts/discourse/components/d-button.js.es6 b/app/assets/javascripts/discourse/components/d-button.js.es6
index c56e1b6b34a..13e36edc717 100644
--- a/app/assets/javascripts/discourse/components/d-button.js.es6
+++ b/app/assets/javascripts/discourse/components/d-button.js.es6
@@ -6,7 +6,7 @@ export default Ember.Component.extend({
tagName: 'button',
classNameBindings: [':btn', 'noText', 'btnType'],
- attributeBindings: ['disabled', 'translatedTitle:title', 'tabindex'],
+ attributeBindings: ['disabled', 'translatedTitle:title', 'ariaLabel:aria-label', 'tabindex'],
btnIcon: Ember.computed.notEmpty('icon'),
@@ -23,7 +23,7 @@ export default Ember.Component.extend({
@computed("title")
translatedTitle(title) {
- return title ? I18n.t(title) : this.get('translatedLabel');
+ if (title) return I18n.t(title);
},
@computed("label")
@@ -31,6 +31,11 @@ export default Ember.Component.extend({
if (label) return I18n.t(label);
},
+ @computed("translatedTitle", "translatedLabel")
+ ariaLabel(translatedTitle, translatedLabel) {
+ return translatedTitle ? translatedTitle : translatedLabel;
+ },
+
click() {
this.sendAction("action", this.get("actionParam"));
return false;
diff --git a/app/assets/javascripts/discourse/widgets/button.js.es6 b/app/assets/javascripts/discourse/widgets/button.js.es6
index aa65deae5e1..b9b288676a2 100644
--- a/app/assets/javascripts/discourse/widgets/button.js.es6
+++ b/app/assets/javascripts/discourse/widgets/button.js.es6
@@ -32,11 +32,14 @@ export const ButtonClass = {
let title;
if (attrs.title) {
title = I18n.t(attrs.title, attrs.titleOptions);
- } else if (attrs.label) {
- title = I18n.t(attrs.label, attrs.labelOptions);
}
- const attributes = { "aria-label": title, title };
+ let label;
+ if (attrs.label) {
+ label = I18n.t(attrs.label, attrs.labelOptions);
+ }
+
+ const attributes = { "aria-label": label, title };
if (attrs.disabled) { attributes.disabled = "true"; }
if (attrs.data) {