dom-repeat: A way to ensure a stable instance to item mapping?

23 views
Skip to first unread message

matt.r....@gmail.com

unread,
Apr 20, 2017, 12:32:22 AM4/20/17
to Polymer
Hello Polymer Team!

For the purpose of using <input> or any focusable component within the <dom-repeat> component, is there a way to ensure a stable template instance to array item mapping? I looked at the source code for the dom-repeat components and it looks like this happens when array items are modified but when a splice is applied to the array, a full re-render is performed. I found that when I use splice to add or remove items to the array, the focus does not behave as expected. The focus will act as if the template instances are bound to the array indexes such that if the n'th element is in focus and an array item with index <n is removed, the n'th element will still be in focus. I would expect that the n'th element (along with the focus) move to the n-1'th element.

It seems that there is enough information passed into the change observer for this to be possible (at least in the use case that I am considering). I think I will be able to make a simple problem specific implementation (without all the render debouncing, frame rate targeting, etc that dom-repeat has). But I don't understand the dom-repeat code enough to be able to properly redesign it. Perhaps someone could point me to the parts of dom-repeat that would need to be modified and I could have a go.

Regards,
Matthew

Matthew Palermo

unread,
Apr 22, 2017, 6:02:58 AM4/22/17
to Polymer
I found a solution in a github issue here: https://github.com/Polymer/polymer/issues/4558
Reply all
Reply to author
Forward
0 new messages