Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing active item after timeline was initialized (controlled) #300

Open
jnachtigall opened this issue Nov 17, 2022 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@jnachtigall
Copy link

Is your feature request related to a problem? Please describe.
Sometimes it would be nice if the activeItemIndex would not only select the active timeline item only on load but could also be controlled (like in a controlled component) later. For instance for using custom prev / next buttons to jump to a certain timeline item. Or setting the active item by some other kind of app state.

Describe the solution you'd like
Since activeItemIndex is unready set to be only used "on load", maybe add another prop like controlledActiveItemIndex. In the end - looking at the code for

const handleOnPrevious = () => {
if (activeTimelineItem > 0) {
const newTimeLineItem = activeTimelineItem - 1;
handleTimelineUpdate(newTimeLineItem);
setActiveTimelineItem(newTimeLineItem);
}
};
-- it just seems to be a matter of calling handleTimelineUpdate(newTimeLineItem) and setActiveTimelineItem(newTimeLineItem)

Describe alternatives you've considered
I looked into a way how maybe handleTimelineUpdate(newTimeLineItem) and setActiveTimelineItem(newTimeLineItem) could be called from outside, but did not find a way. Both functions do not seem to be exposed. Actually, just exposing handleTimelineUpdate(newTimeLineItem) would probably be sufficient as it internally calls setActiveTimelineItem(newTimeLineItem) itself:

const handleTimelineUpdate = useCallback((actvTimelineIndex: number) => {
setItems((lineItems) =>
lineItems.map((item, index) =>
Object.assign({}, item, {
active: index === actvTimelineIndex,
}),
),
);
setActiveTimelineItem(actvTimelineIndex);
if (items) {
if (items.length - 1 === actvTimelineIndex) {
setSlideshowActive(false);
}
}
}, []);

Additional context
Add any other context or screenshots about the feature request here.

@prabhuignoto prabhuignoto self-assigned this Nov 27, 2022
@prabhuignoto prabhuignoto added the enhancement New feature or request label Nov 27, 2022
DrakeXorn added a commit to DrakeXorn/react-chrono that referenced this issue Jan 31, 2023
As requested in prabhuignoto#300
(and also because I needed it 😄), this implements a simple `useEffect`
that updates the `activeTimelineIndex` accordingly.
prabhuignoto pushed a commit that referenced this issue Feb 2, 2023
#320)

As requested in #300
(and also because I needed it 😄), this implements a simple `useEffect`
that updates the `activeTimelineIndex` accordingly.
tony43e added a commit to tony43e/react-chrono that referenced this issue May 4, 2023
…x (#320)

As requested in prabhuignoto/react-chrono#300
(and also because I needed it 😄), this implements a simple `useEffect`
that updates the `activeTimelineIndex` accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants