DEV: adds row index support (#19871)
This commits adds a data-index attribute on each `select-kit-row` DOM node and also makes available `this.index` in each `select-kit-row` template.
This commit is contained in:
parent
f525f722ea
commit
a444023113
|
@ -393,6 +393,24 @@ module("Integration | Component | select-kit/single-select", function (hooks) {
|
|||
);
|
||||
});
|
||||
|
||||
test("row index", async function (assert) {
|
||||
this.setProperties({
|
||||
content: [
|
||||
{ id: 1, name: "john" },
|
||||
{ id: 2, name: "jane" },
|
||||
],
|
||||
value: null,
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<SingleSelect @value={{this.value}} @content={{this.content}} />`
|
||||
);
|
||||
await this.subject.expand();
|
||||
|
||||
assert.dom('.select-kit-row[data-index="0"][data-value="1"]').exists();
|
||||
assert.dom('.select-kit-row[data-index="1"][data-value="2"]').exists();
|
||||
});
|
||||
|
||||
test("options.verticalOffset", async function (assert) {
|
||||
setDefaultState(this, { verticalOffset: -50 });
|
||||
await render(hbs`
|
||||
|
|
|
@ -18,6 +18,7 @@ export default Component.extend(UtilsMixin, {
|
|||
"title",
|
||||
"rowValue:data-value",
|
||||
"rowName:data-name",
|
||||
"index:data-index",
|
||||
"role",
|
||||
"ariaChecked:aria-checked",
|
||||
"guid:data-guid",
|
||||
|
@ -30,6 +31,7 @@ export default Component.extend(UtilsMixin, {
|
|||
"isNone:none",
|
||||
"item.classNames",
|
||||
],
|
||||
index: 0,
|
||||
|
||||
role: "menuitemradio",
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
{{#if this.collection.content.length}}
|
||||
<ul class="select-kit-collection" aria-live="polite" role="menu">
|
||||
{{#each this.collection.content as |item|}}
|
||||
{{#each this.collection.content as |item index|}}
|
||||
{{component
|
||||
(component-for-row this.collection.identifier item this.selectKit)
|
||||
index=index
|
||||
item=item
|
||||
value=this.value
|
||||
selectKit=this.selectKit
|
||||
}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
|
Loading…
Reference in New Issue