refactor: use ItemNavigation optimally #2585
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change refactors the usage of
ItemNavigation.js
for all components except date/time related ones (which will be addressed separately).Changes:
getItemsCallback
can be set in the constructor, this is the preferable way of passing it. This also eliminates the need of a separateinitItemNavigation
function that many components had as they needed 2 lines of code -new ItemNavigation
and to set the callback.focusin
event forTimeline.js
as it did not update the item navigation like the rest of the components whenever the user clicks with the mouse.ItemNavigation.prototype.current
any more (it is marked as deprecated). Always callupdate
instead.ItemNavigation.prototype.currentIndex
any more (it is private). Always callupdate
instead.ItemNavigation.prototype.focusCurrent
any more (marked as deprecated). Use the item that was passed toupdate
directly (seeTokenizer.js
for example).getItemsCallback
inonBeforeRendering
- it is a callback exactly for the reason that based on the state of the component, it may return completely different data (seeAvatarGroup.js
for an example)Summary:
ItemNavigation
in the constructor of the component and pass the callback therefocusin
event for your component and callupdate
with the newly focused item to synchronize the item navigation. Do not usecurrent
orcurrentIndex
.