How to have the caption not show by default? #279
-
I want the captions to be not shown by default. This here works but it's hacky and there's a flash of the caption whenever a slide becomes active. <Lightbox
index={index}
plugins={[Fullscreen, Captions]}
captions={{ ref: captionsRef, showToggle: true }}
on={{
entered: () => {
captionsRef.current?.hide();
},
}}
slides={images.map((image) => ({
src: image.url,
alt: image.name,
title: image.name,
}))}
open={index >= 0}
close={() => setIndex(-1)}
/> |
Beta Was this translation helpful? Give feedback.
Answered by
igordanchenko
Jun 13, 2024
Replies: 1 comment 3 replies
-
Hi there! Thank you for bringing up this use case. While it's possible to eliminate the initial captions flash in the current version, the DX is far from perfect. const [index, setIndex] = React.useState(-1);
const hideCaptions = React.useRef(false);
const handleCaptionsRef = React.useCallback(
(captionsRef: CaptionsRef | null) => {
if (captionsRef && hideCaptions.current) {
hideCaptions.current = false;
captionsRef.hide();
}
},
[]
);
// ...
<Lightbox
index={index}
plugins={[Fullscreen, Captions]}
captions={{ ref: handleCaptionsRef, showToggle: true }}
on={{
entering: () => {
hideCaptions.current = true;
},
}}
slides={slides.map((slide) => ({
...slide,
title: "Slide title",
description: "Slide description",
}))}
open={index >= 0}
close={() => setIndex(-1)}
/> https://stackblitz.com/edit/yet-another-react-lightbox-279?file=src%2FApp.tsx I'll add a configuration option for the initial state. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Fexxix
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there! Thank you for bringing up this use case. While it's possible to eliminate the initial captions flash in the current version, the DX is far from perfect.