mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 13:35:20 -05:00
DEV: allows buttons to define aria-label (#9747)
This commit is contained in:
@@ -5,12 +5,17 @@ import discourseComputed from "discourse-common/utils/decorators";
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
|
||||
export default Component.extend({
|
||||
tagName: "button",
|
||||
// subclasses need this
|
||||
layoutName: "components/d-button",
|
||||
|
||||
form: null,
|
||||
|
||||
type: "button",
|
||||
title: null,
|
||||
translatedTitle: null,
|
||||
label: null,
|
||||
translatedLabel: null,
|
||||
ariaLabel: null,
|
||||
translatedAriaLabel: null,
|
||||
|
||||
isLoading: computed({
|
||||
set(key, value) {
|
||||
@@ -19,7 +24,6 @@ export default Component.extend({
|
||||
}
|
||||
}),
|
||||
|
||||
tagName: "button",
|
||||
classNameBindings: [
|
||||
"isLoading:is-loading",
|
||||
"btnLink::btn",
|
||||
@@ -30,8 +34,8 @@ export default Component.extend({
|
||||
attributeBindings: [
|
||||
"form",
|
||||
"isDisabled:disabled",
|
||||
"translatedTitle:title",
|
||||
"translatedLabel:aria-label",
|
||||
"computedTitle:title",
|
||||
"computedAriaLabel:aria-label",
|
||||
"tabindex",
|
||||
"type"
|
||||
],
|
||||
@@ -46,7 +50,7 @@ export default Component.extend({
|
||||
|
||||
btnLink: equal("display", "link"),
|
||||
|
||||
@discourseComputed("icon", "translatedLabel")
|
||||
@discourseComputed("icon", "computedLabel")
|
||||
btnType(icon, translatedLabel) {
|
||||
if (icon) {
|
||||
return translatedLabel ? "btn-icon-text" : "btn-icon";
|
||||
@@ -55,28 +59,25 @@ export default Component.extend({
|
||||
}
|
||||
},
|
||||
|
||||
noText: empty("translatedLabel"),
|
||||
noText: empty("computedLabel"),
|
||||
|
||||
@discourseComputed("title")
|
||||
translatedTitle: {
|
||||
get() {
|
||||
if (this._translatedTitle) return this._translatedTitle;
|
||||
if (this.title) return I18n.t(this.title);
|
||||
},
|
||||
set(value) {
|
||||
return (this._translatedTitle = value);
|
||||
}
|
||||
@discourseComputed("title", "translatedTitle")
|
||||
computedTitle(title, translatedTitle) {
|
||||
if (this.title) return I18n.t(title);
|
||||
return translatedTitle;
|
||||
},
|
||||
|
||||
@discourseComputed("label")
|
||||
translatedLabel: {
|
||||
get() {
|
||||
if (this._translatedLabel) return this._translatedLabel;
|
||||
if (this.label) return I18n.t(this.label);
|
||||
},
|
||||
set(value) {
|
||||
return (this._translatedLabel = value);
|
||||
}
|
||||
@discourseComputed("label", "translatedLabel")
|
||||
computedLabel(label, translatedLabel) {
|
||||
if (this.label) return I18n.t(label);
|
||||
return translatedLabel;
|
||||
},
|
||||
|
||||
@discourseComputed("ariaLabel", "translatedAriaLabel", "computedLabel")
|
||||
computedAriaLabel(ariaLabel, translatedAriaLabel, computedLabel) {
|
||||
if (ariaLabel) return I18n.t(ariaLabel);
|
||||
if (translatedAriaLabel) return translatedAriaLabel;
|
||||
return computedLabel;
|
||||
},
|
||||
|
||||
click() {
|
||||
|
||||
@@ -28,6 +28,10 @@ export function registerTopicFooterButton(button) {
|
||||
label: null,
|
||||
translatedLabel: null,
|
||||
|
||||
// local key path for aria label
|
||||
ariaLabel: null,
|
||||
translatedAriaLabel: null,
|
||||
|
||||
// is this button disaplyed in the mobile dropdown or as an inline button ?
|
||||
dropdown: false,
|
||||
|
||||
@@ -98,6 +102,15 @@ export function getTopicFooterButtons() {
|
||||
? I18n.t(label)
|
||||
: _compute(button, "translatedLabel");
|
||||
|
||||
const ariaLabel = _compute(button, "ariaLabel");
|
||||
if (ariaLabel) {
|
||||
discourseComputedButon.ariaLabel = I18n.t(ariaLabel);
|
||||
} else {
|
||||
const translatedAriaLabel = _compute(button, "translatedAriaLabel");
|
||||
discourseComputedButon.ariaLabel =
|
||||
translatedAriaLabel || discourseComputedButon.label;
|
||||
}
|
||||
|
||||
const title = _compute(button, "title");
|
||||
discourseComputedButon.title = title
|
||||
? I18n.t(title)
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{#if translatedLabel}}
|
||||
<span class="d-button-label">{{html-safe translatedLabel}}{{#if ellipsis}}…{{/if}}</span>
|
||||
{{#if computedLabel}}
|
||||
<span class="d-button-label">{{html-safe computedLabel}}{{#if ellipsis}}…{{/if}}</span>
|
||||
{{/if}}
|
||||
|
||||
{{yield}}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
icon=button.icon
|
||||
translatedLabel=button.label
|
||||
translatedTitle=button.title
|
||||
translatedAriaLabel=button.ariaLabel
|
||||
disabled=button.disabled}}
|
||||
{{/each}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user