Skip to content

Commit

Permalink
Populate aria-owns attribute on iron-list + test
Browse files Browse the repository at this point in the history
  • Loading branch information
hcarmona committed Oct 9, 2019
1 parent 30eb60a commit 10a7ae4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 7 additions & 0 deletions iron-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -1323,10 +1323,17 @@ Polymer({
}
});
} else {
let order = [];
this._iterateItems(function(pidx, vidx) {
this.translate3d(0, y + 'px', 0, this._physicalItems[pidx]);
y += this._physicalSizes[pidx];
if (this._physicalItems[pidx].id) {
order.push(this._physicalItems[pidx].id);
}
});
if (order.length) {
this.setAttribute('aria-owns', order.join(' '));
}
}
},

Expand Down
34 changes: 33 additions & 1 deletion test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<test-fixture id="trivialList">
<template>
<x-list></x-list>
<x-list id$="tl[[index]]"></x-list>
</template>
</test-fixture>

Expand Down Expand Up @@ -145,6 +145,38 @@
assert.equal(list.firstVisibleIndex, 99);
});

test('expected aria-owns while scrolling', function() {
list.items = buildDataSet(100);
PolymerFlush();

const getExpectedAriaOwns = () => {
return
// Physical children.
Array.from(list.querySelectorAll('x-list'))

// Skip selected node.
.filter(child => child.getBoundingClientRect().top >= -10000)

// Sort by |top|.
.sort((left, right) => left.getBoundingClientRect().top - right.getBoundingClientRect().top)

// Get IDs.
.map(child => child.id)

// Create expected |aria-owned|.
.join(' ');
};

// Make sure we're virtualizing nodes.
assert.isTrue(Array.from(list.querySelectorAll('x-list')).length < list.items.length);

// Scroll by 7 because it's not a 'nice round number'.
for (let i = 0; i < list.items.length; i += 7) {
list.scrollToIndex(i);
assert.equal(list.getAttribute('aria-owns'), getExpectedAriaOwns());
}
});

test('scroll to index while not attached', function() {
var tmpList = document.createElement('iron-list');
dom(tmpList).appendChild(document.createElement('template'));
Expand Down

0 comments on commit 10a7ae4

Please sign in to comment.