Closed jogibear9988 closed 5 years ago
What would be the use case?
If you save the item on each child (e.g. as we do for <contact-element>
), it should be as simple as:
scroller.updateElement = (elem, item) => elem.item = item;
const elementForItem = (item) => scroller.children.find(elem => elem.item === item);
const itemForElement = (elem) => elem.item;
In iron-grid I needed it to the get selected Elemnt from the selected item to focus an inner child on selection change.
@jogibear9988 interesting, can you provide more details? E.g. do you want to focus only when receiving the data, or programmatically trigger it when the user clicks on the element?
You could have a container-like custom element that forwards focus to the focusable child when selected.
You can as well configure its shadowRoot with delegatesFocus: true
, which basically makes the element focusable and forwards the focus to the first focusable child if any. In this case you wouldn't need a selected property, but just call focus()
on the container custom element, or just set the autofocus
attribute on it
Is there a API to get the underlying item for an element? And one to get the Element for and underlying item?
I've needed this several times when I used iron-list