react-responsive-carousel icon indicating copy to clipboard operation
react-responsive-carousel copied to clipboard

Support for clickable slides, with hyperlinks

Open ajmas opened this issue 7 years ago • 9 comments

From what I can tell it is not possible currently to add a hyperlink to a slide, such that when clicking on it would follow the referenced page?

For example:

        <div>
            <a href="http://github.com/"><img src="images/2.jpeg" /></a>
            <p className="legend">Legend 1</p>
        </div>
        <div>
            <a href="http://localhost:2020/"><img src="images/2.jpeg" /></a>
            <p className="legend">Legend 2</p>
        </div>
        <div>
            <img src="images/3.jpeg" />
            <p className="legend">Legend 3</p>
        </div>
        <div>
            <img src="images/4.jpeg" />
            <p className="legend">Legend 4</p>
        </div>
        <div>
            <img src="images/5.jpeg" />
            <p className="legend">Legend 5</p>
        </div>
        <div>
            <img src="images/6.jpeg" />
            <p className="legend">Legend 6</p>
        </div>

The expectation here is click on slide 1 and 2 would take me to referenced page.

I did try using onClickItem, to hoping this could help, but it just returns the slide number, when doesn't allow me to access the content to process myself.

I did also try in the sandbox: https://codesandbox.io/s/rql0ovl5m

ajmas avatar Dec 24 '18 03:12 ajmas

I was having trouble with this too. I noticed that the hyperlink was there, but only 17 pixels height for some reason. I was able to get it to work by putting another div around the image:

    <Carousel autoPlay>
      <div>
        <a href="http://www.github.com" target="_blank">
          <div>
            <img src="http://lorempixel.com/output/cats-q-c-640-480-1.jpg" />
          </div>
        </a>
        <p className="legend">Legend 1</p>
      </div>

https://codesandbox.io/s/l47nyr4qzz

danthul avatar Mar 03 '19 21:03 danthul

You should just have to make your anchor tag display: block to fill the space, it's an inline element otherwise.

MichaelWheldon avatar Jul 06 '19 02:07 MichaelWheldon

You should just have to make your anchor tag display: block to fill the space, it's an inline element otherwise.

It worked for me like a charm. Thanks a lot.

jessecaii avatar Jul 07 '20 02:07 jessecaii

I'll close this issue since there is a solution that appears to work for others - I am no longer in a position to test myself, so I'll trust them on it.

ajmas avatar Jul 07 '20 04:07 ajmas

i handle it by using onClickItem props. <Carousel onClickItem={(index) => { window.open(art.imageUrls[index].url) }} >

Jongmun-Park avatar Mar 02 '21 06:03 Jongmun-Park

onClickItem={(index) => { window.open(art.imageUrls[index].url) }}

it doesn't work if using animationHandler="fade"

ilhamgum avatar Sep 19 '22 08:09 ilhamgum

After hours of research and none of the above working, I found that the conflict is changed by animationHandler="fade" , I removed it and everything worked like a charm

emontes avatar Oct 12 '22 22:10 emontes

Yes, I have faced the same issue of routing or a tag link is not working when there is added this animationHandler="fade" props

bhavinzwt avatar Jun 13 '23 13:06 bhavinzwt

I can confirm: using animation type fade doesn't work with onClickItem because slides get z-index: -2. As a workaround I just used this style:

.carousel .slide.selected {
    z-index: 0 !important;
}

darkwebdev avatar Feb 28 '25 15:02 darkwebdev