mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1799877 - Allow using { l10n-id, l10n-args } object when setting notification label. r=dao,mstriemer
This matches the existing behavior of NotificationBox.appendNotification(). Differential Revision: https://phabricator.services.mozilla.com/D161893
This commit is contained in:
parent
ed168ca161
commit
1b39667206
@ -122,6 +122,26 @@ function testtag_notification_eventCallback(expectedEvents, ntf, testName)
|
||||
|
||||
var tests =
|
||||
[
|
||||
{
|
||||
test(nb, ntf) {
|
||||
ntf = nb.appendNotification("mutable", {
|
||||
label: "Original",
|
||||
priority: nb.PRIORITY_INFO_LOW,
|
||||
}, testtag_notificationbox_buttons);
|
||||
|
||||
ntf.label = "Changed string";
|
||||
SimpleTest.is(ntf.messageText.textContent, "Changed string", "set notification label with string");
|
||||
|
||||
ntf.label = { "l10n-id": "foo-bar" };
|
||||
const message = ntf.messageText.querySelector("span");
|
||||
SimpleTest.is(message.dataset.l10nId, "foo-bar", "set notification label with l10n id");
|
||||
return ntf;
|
||||
},
|
||||
result(nb, ntf) {
|
||||
nb.removeNotification(ntf);
|
||||
testtag_notificationbox_State(nb, "set notification label", null, 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
test(nb, ntf) {
|
||||
// append a new notification
|
||||
|
@ -508,10 +508,26 @@
|
||||
|
||||
/**
|
||||
* Changes the text of an existing notification. If the notification was
|
||||
* created with a custom fragment, it will be overwritten with plain text.
|
||||
* created with a custom fragment, it will be overwritten with plain text
|
||||
* or a localized message.
|
||||
*
|
||||
* @param {string | { "l10n-id": string, "l10n-args"?: string }} value
|
||||
*/
|
||||
set label(value) {
|
||||
this.messageText.textContent = value;
|
||||
if (value && typeof value == "object" && "l10n-id" in value) {
|
||||
const message = document.createElement("span");
|
||||
document.l10n.setAttributes(
|
||||
message,
|
||||
value["l10n-id"],
|
||||
value["l10n-args"]
|
||||
);
|
||||
while (this.messageText.firstChild) {
|
||||
this.messageText.firstChild.remove();
|
||||
}
|
||||
this.messageText.appendChild(message);
|
||||
} else {
|
||||
this.messageText.textContent = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -709,8 +725,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the text of an existing notification. If the notification was
|
||||
* created with a custom fragment, it will be overwritten with plain text
|
||||
* or a localized message.
|
||||
*
|
||||
* @param {string | { "l10n-id": string, "l10n-args"?: string }} value
|
||||
*/
|
||||
set label(value) {
|
||||
this.messageText.textContent = value;
|
||||
if (value && typeof value == "object" && "l10n-id" in value) {
|
||||
const message = document.createElement("span");
|
||||
document.l10n.setAttributes(
|
||||
message,
|
||||
value["l10n-id"],
|
||||
value["l10n-args"]
|
||||
);
|
||||
while (this.messageText.firstChild) {
|
||||
this.messageText.firstChild.remove();
|
||||
}
|
||||
this.messageText.appendChild(message);
|
||||
} else {
|
||||
this.messageText.textContent = value;
|
||||
}
|
||||
this.setAlertRole();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user