mirror of
https://github.com/discourse/discourse.git
synced 2025-06-08 00:27:32 +08:00
cleaner title attribute for select-box
This commit is contained in:
@ -16,20 +16,24 @@ export default DropdownSelectBoxComponent.extend({
|
|||||||
|
|
||||||
value: Em.computed.alias("notificationLevel"),
|
value: Em.computed.alias("notificationLevel"),
|
||||||
|
|
||||||
@computed("value")
|
@computed("selectedDetails")
|
||||||
icon(value) {
|
icon(details) {
|
||||||
const details = buttonDetails(value);
|
|
||||||
return iconHTML(details.icon, {class: details.key}).htmlSafe();
|
return iconHTML(details.icon, {class: details.key}).htmlSafe();
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("value", "showFullTitle")
|
@computed("selectedDetails.key", "i18nPrefix")
|
||||||
generatedHeadertext(value, showFullTitle) {
|
selectedTitle(key, prefix) {
|
||||||
if (showFullTitle) {
|
return I18n.t(`${prefix}.${key}.title`);
|
||||||
const details = buttonDetails(value);
|
},
|
||||||
return I18n.t(`${this.get("i18nPrefix")}.${details.key}.title`);
|
|
||||||
} else {
|
@computed("value")
|
||||||
return null;
|
selectedDetails(value) {
|
||||||
}
|
return buttonDetails(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
@computed("selectedTitle", "showFullTitle")
|
||||||
|
generatedHeadertext(selectedTitle, showFullTitle) {
|
||||||
|
return showFullTitle ? selectedTitle : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
|
@ -308,6 +308,15 @@ export default Ember.Component.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed("headerText", "selectedContent", "textKey")
|
||||||
|
selectedTitle(headerText, selectedContent, textKey) {
|
||||||
|
if (Ember.isNone(selectedContent)) {
|
||||||
|
return headerText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedContent[textKey];
|
||||||
|
},
|
||||||
|
|
||||||
@computed("headerText", "dynamicHeaderText", "selectedContent", "textKey", "clearSelectionLabel")
|
@computed("headerText", "dynamicHeaderText", "selectedContent", "textKey", "clearSelectionLabel")
|
||||||
generatedHeadertext(headerText, dynamic, selectedContent, textKey, clearSelectionLabel) {
|
generatedHeadertext(headerText, dynamic, selectedContent, textKey, clearSelectionLabel) {
|
||||||
if (dynamic && !Ember.isNone(selectedContent)) {
|
if (dynamic && !Ember.isNone(selectedContent)) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<button
|
<button
|
||||||
class="btn {{if text 'btn-icon-text' 'no-text btn-icon'}}"
|
class="btn {{if text 'btn-icon-text' 'no-text btn-icon'}}"
|
||||||
aria-label="{{text}}"
|
aria-label="{{selectedTitle}}"
|
||||||
type="button"
|
type="button"
|
||||||
title="{{text}}">
|
title="{{selectedTitle}}">
|
||||||
|
|
||||||
{{{icon}}}
|
{{{icon}}}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
{{component selectBoxHeaderComponent
|
{{component selectBoxHeaderComponent
|
||||||
text=generatedHeadertext
|
text=generatedHeadertext
|
||||||
|
selectedTitle=selectedTitle
|
||||||
focused=focused
|
focused=focused
|
||||||
caretUpIcon=caretUpIcon
|
caretUpIcon=caretUpIcon
|
||||||
caretDownIcon=caretDownIcon
|
caretDownIcon=caretDownIcon
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{{d-icon icon class="icon"}}
|
{{d-icon icon class="icon"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<span class="current-selection">
|
<span class="current-selection" title={{selectedTitle}}>
|
||||||
{{text}}
|
{{text}}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
23
test/javascripts/components/dropdown-select-box-test.js.es6
Normal file
23
test/javascripts/components/dropdown-select-box-test.js.es6
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import componentTest from 'helpers/component-test';
|
||||||
|
|
||||||
|
moduleForComponent('dropdown-select-box', { integration: true });
|
||||||
|
|
||||||
|
componentTest('the header has a title', {
|
||||||
|
template: '{{dropdown-select-box content=content value=value}}',
|
||||||
|
|
||||||
|
beforeEach() {
|
||||||
|
this.set("value", 1);
|
||||||
|
this.set("content", [{ id: 1, text: "apple" }, { id: 2, text: "peach" }]);
|
||||||
|
},
|
||||||
|
|
||||||
|
test(assert) {
|
||||||
|
andThen(() => {
|
||||||
|
assert.equal(find(".select-box-header .btn").attr("title"), "apple", "it has the correct title");
|
||||||
|
});
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
this.set("value", 2);
|
||||||
|
assert.equal(find(".select-box-header .btn").attr("title"), "peach", "it correctly changes the title");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,34 @@
|
|||||||
|
import componentTest from 'helpers/component-test';
|
||||||
|
import Topic from 'discourse/models/topic';
|
||||||
|
|
||||||
|
const buildTopic = function() {
|
||||||
|
return Topic.create({
|
||||||
|
id: 4563,
|
||||||
|
title: "Qunit Test Topic",
|
||||||
|
details: {
|
||||||
|
notification_level: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
moduleForComponent('topic-notifications-button', { integration: true });
|
||||||
|
|
||||||
|
componentTest('the header has a localized title', {
|
||||||
|
template: '{{topic-notifications-button topic=topic}}',
|
||||||
|
|
||||||
|
beforeEach() {
|
||||||
|
this.set("topic", buildTopic());
|
||||||
|
},
|
||||||
|
|
||||||
|
test(assert) {
|
||||||
|
andThen(() => {
|
||||||
|
assert.equal(find(".select-box-header .btn").attr("title"), "Normal", "it has the correct title");
|
||||||
|
});
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
this.set("topic.details.notification_level", 2);
|
||||||
|
assert.equal(find(".select-box-header .btn").attr("title"), "Tracking", "it correctly changes the title");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
Reference in New Issue
Block a user