mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 20:24:40 +08:00
DEV: adds support for lang attribute in select-kit (#11741)
This commit is contained in:
@ -99,6 +99,7 @@
|
|||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{combo-box
|
{{combo-box
|
||||||
valueProperty="value"
|
valueProperty="value"
|
||||||
|
langProperty="value"
|
||||||
content=availableLocales
|
content=availableLocales
|
||||||
value=model.locale
|
value=model.locale
|
||||||
onChange=(action (mut model.locale))
|
onChange=(action (mut model.locale))
|
||||||
|
@ -313,4 +313,35 @@ discourseModule("Integration | Component | select-kit/single-select", function (
|
|||||||
assert.equal(row.title(), "JACKSON");
|
assert.equal(row.title(), "JACKSON");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
componentTest("langProperty", {
|
||||||
|
template:
|
||||||
|
'{{single-select langProperty="foo" value=value content=content}}',
|
||||||
|
|
||||||
|
beforeEach() {
|
||||||
|
this.setProperties({
|
||||||
|
content: [{ id: 1, name: "john", foo: "be" }],
|
||||||
|
value: null,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async test(assert) {
|
||||||
|
assert.equal(
|
||||||
|
this.subject.header().el()[0].querySelector(".selected-name").lang,
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.subject.expand();
|
||||||
|
|
||||||
|
const row = this.subject.rowByValue(1);
|
||||||
|
assert.equal(row.el()[0].lang, "be");
|
||||||
|
|
||||||
|
await this.subject.selectRowByValue(1);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
this.subject.header().el()[0].querySelector(".selected-name").lang,
|
||||||
|
"be"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -58,6 +58,7 @@ export default Component.extend(
|
|||||||
multiSelect: false,
|
multiSelect: false,
|
||||||
labelProperty: null,
|
labelProperty: null,
|
||||||
titleProperty: null,
|
titleProperty: null,
|
||||||
|
langProperty: null,
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
@ -79,6 +80,7 @@ export default Component.extend(
|
|||||||
nameProperty: this.nameProperty,
|
nameProperty: this.nameProperty,
|
||||||
labelProperty: this.labelProperty,
|
labelProperty: this.labelProperty,
|
||||||
titleProperty: this.titleProperty,
|
titleProperty: this.titleProperty,
|
||||||
|
langProperty: this.langProperty,
|
||||||
options: EmberObject.create(),
|
options: EmberObject.create(),
|
||||||
|
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
@ -5,6 +5,7 @@ import UtilsMixin from "select-kit/mixins/utils";
|
|||||||
import { guidFor } from "@ember/object/internals";
|
import { guidFor } from "@ember/object/internals";
|
||||||
import layout from "select-kit/templates/components/select-kit/select-kit-row";
|
import layout from "select-kit/templates/components/select-kit/select-kit-row";
|
||||||
import { makeArray } from "discourse-common/lib/helpers";
|
import { makeArray } from "discourse-common/lib/helpers";
|
||||||
|
import { reads } from "@ember/object/computed";
|
||||||
|
|
||||||
export default Component.extend(UtilsMixin, {
|
export default Component.extend(UtilsMixin, {
|
||||||
layout,
|
layout,
|
||||||
@ -18,6 +19,7 @@ export default Component.extend(UtilsMixin, {
|
|||||||
"rowName:data-name",
|
"rowName:data-name",
|
||||||
"ariaLabel:aria-label",
|
"ariaLabel:aria-label",
|
||||||
"guid:data-guid",
|
"guid:data-guid",
|
||||||
|
"rowLang:lang",
|
||||||
],
|
],
|
||||||
classNameBindings: [
|
classNameBindings: [
|
||||||
"isHighlighted",
|
"isHighlighted",
|
||||||
@ -47,6 +49,8 @@ export default Component.extend(UtilsMixin, {
|
|||||||
return guidFor(this.item);
|
return guidFor(this.item);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
lang: reads("item.lang"),
|
||||||
|
|
||||||
ariaLabel: computed("item.ariaLabel", "title", function () {
|
ariaLabel: computed("item.ariaLabel", "title", function () {
|
||||||
return this.getProperty(this.item, "ariaLabel") || this.title;
|
return this.getProperty(this.item, "ariaLabel") || this.title;
|
||||||
}),
|
}),
|
||||||
@ -82,6 +86,7 @@ export default Component.extend(UtilsMixin, {
|
|||||||
rowValue: this.getValue(this.item),
|
rowValue: this.getValue(this.item),
|
||||||
rowLabel: this.getProperty(this.item, "labelProperty"),
|
rowLabel: this.getProperty(this.item, "labelProperty"),
|
||||||
rowTitle: this.getProperty(this.item, "titleProperty"),
|
rowTitle: this.getProperty(this.item, "titleProperty"),
|
||||||
|
rowLang: this.getProperty(this.item, "langProperty"),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -3,12 +3,16 @@ import Component from "@ember/component";
|
|||||||
import UtilsMixin from "select-kit/mixins/utils";
|
import UtilsMixin from "select-kit/mixins/utils";
|
||||||
import layout from "select-kit/templates/components/selected-name";
|
import layout from "select-kit/templates/components/selected-name";
|
||||||
import { makeArray } from "discourse-common/lib/helpers";
|
import { makeArray } from "discourse-common/lib/helpers";
|
||||||
|
import { reads } from "@ember/object/computed";
|
||||||
|
|
||||||
export default Component.extend(UtilsMixin, {
|
export default Component.extend(UtilsMixin, {
|
||||||
tagName: "",
|
tagName: "",
|
||||||
layout,
|
layout,
|
||||||
name: null,
|
name: null,
|
||||||
value: null,
|
value: null,
|
||||||
|
headerTitle: null,
|
||||||
|
headerLang: null,
|
||||||
|
headerLabel: null,
|
||||||
|
|
||||||
@action
|
@action
|
||||||
onSelectedNameClick() {
|
onSelectedNameClick() {
|
||||||
@ -25,12 +29,15 @@ export default Component.extend(UtilsMixin, {
|
|||||||
this.setProperties({
|
this.setProperties({
|
||||||
headerLabel: this.getProperty(this.item, "labelProperty"),
|
headerLabel: this.getProperty(this.item, "labelProperty"),
|
||||||
headerTitle: this.getProperty(this.item, "titleProperty"),
|
headerTitle: this.getProperty(this.item, "titleProperty"),
|
||||||
|
headerLang: this.getProperty(this.item, "langProperty"),
|
||||||
name: this.getName(this.item),
|
name: this.getName(this.item),
|
||||||
value:
|
value:
|
||||||
this.item === this.selectKit.noneItem ? null : this.getValue(this.item),
|
this.item === this.selectKit.noneItem ? null : this.getValue(this.item),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
lang: reads("headerLang"),
|
||||||
|
|
||||||
ariaLabel: computed("item", "sanitizedTitle", function () {
|
ariaLabel: computed("item", "sanitizedTitle", function () {
|
||||||
return this._safeProperty("ariaLabel", this.item) || this.sanitizedTitle;
|
return this._safeProperty("ariaLabel", this.item) || this.sanitizedTitle;
|
||||||
}),
|
}),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{{#if selectKit.options.showFullTitle}}
|
{{#if selectKit.options.showFullTitle}}
|
||||||
<div {{action "onSelectedNameClick"}} tabindex="0" title={{title}} data-value={{value}} data-name={{name}} class="select-kit-selected-name selected-name choice">
|
<div lang={{lang}} {{action "onSelectedNameClick"}} tabindex="0" title={{title}} data-value={{value}} data-name={{name}} class="select-kit-selected-name selected-name choice">
|
||||||
{{#if item.icon}}
|
{{#if item.icon}}
|
||||||
{{d-icon item.icon}}
|
{{d-icon item.icon}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
@ -23,7 +23,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{#if item.icon}}
|
{{#if item.icon}}
|
||||||
<div tabindex="0" class="select-kit-selected-name selected-name choice">
|
<div lang={{lang}} tabindex="0" class="select-kit-selected-name selected-name choice">
|
||||||
{{d-icon item.icon}}
|
{{d-icon item.icon}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
Reference in New Issue
Block a user