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

Current Item #22

Closed
WassimHakim opened this issue Sep 13, 2019 · 3 comments
Closed

Current Item #22

WassimHakim opened this issue Sep 13, 2019 · 3 comments

Comments

@WassimHakim
Copy link

WassimHakim commented Sep 13, 2019

Why doesn't the current item have a custom class. if we can add it when navigating, how can we do that?

@sag1v
Copy link
Owner

sag1v commented Sep 13, 2019

You can do it by tracking the current active item yourself via the the change handlers, for example onNextEnd and onPrevEnd.
See the docs for more details.

here is a running example

Here is a sample gist:

const items = [1, 2, 3, 4, 5, 6, 7, 8];

function App() {
  const [currentItem, setCurrentItem] = React.useState(0);
  const onCurrentChange = current => {
    setCurrentItem(current.index)
  }

  return (
    <div className="App">
      <Carousel
        onNextEnd={onCurrentChange}
        onPrevEnd={onCurrentChange}
      >
        {items.map((item, i) => {
          const className = currentItem === i ? "active" : "";
          return (
            <Item key={item} className={className}>
              {item}
            </Item>
          );
        })}
      </Carousel>
    </div>
  );
}

I'm going to close this as its not a bug or a feature request, and i think you got an answer to your question.
If you think you didn't get a proper solution then feel free to re-open this issue. 🙂

@sag1v sag1v closed this as completed Sep 13, 2019
@WassimHakim
Copy link
Author

It worked thanks. One more question, how do we configure an infinite loop on it?

@sag1v
Copy link
Owner

sag1v commented Sep 17, 2019

Infinite loop is not supported yet see #9 , i didn't have much time to work on it. PR is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants