Skip to content

Conversation

@KumJungMin
Copy link
Contributor

Defect Fixes

Cause

  • The Galleria component is only mounted when props.value is non-empty (return ObjectUtils.isNotEmpty(props.value) && createGalleria()), so it doesn’t exist in the DOM until data arrives.
  • By default, CSSTransition only runs its enter lifecycle when its in prop changes from false to true, so the initial mount skips onEntering, causing the overlay callbacks never to fire on first show.

Solution

  • Add the appear: true flag to the transition props so that the enter lifecycle always runs on the first mount:
const transitionProps = mergeProps(
  {
    classNames: cx('transition'),
    in: visibleState,
    timeout: { enter: 150, exit: 150 },
+   appear: true,          // ensure onEnter/onEntering run on initial mount
     ...
  },
  ptm('transition')
);

Test

Sample Code
import { Galleria } from '@/components/lib/galleria/Galleria';
import { useRef, useState } from 'react';

export function BasicDoc() {
    const [galleriaImages, setGalleriaImages] = useState([]);
    const [galleriaImagesActiveIndex, setGalleriaImagesActiveIndex] = useState(0);
    const galleriaRef = useRef(null);
    const galleriaItemTemplate = (item) => (
        <img
            src={item}
            alt=""
            style={{
                maxWidth: '100vw',
                display: 'block',
                padding: '0 10px',
                maxHeight: '90vh'
            }}
        />
    );
    const galleriaThumbnailTemplate = (item) => <img src={item} alt="" style={{ height: '100px', marginLeft: '10px' }} />;

    return (
        <>
            <button
                type="button"
                onClick={() => {
                    setGalleriaImages(['https://picsum.photos/200/200', 'https://picsum.photos/300/300', 'https://picsum.photos/200/300', 'https://picsum.photos/300/200']);
                    setGalleriaImagesActiveIndex(0);

                    galleriaRef.current?.show();
                }}
            >
                Not Working Version
            </button>

            <Galleria
                ref={galleriaRef}
                value={galleriaImages}
                item={galleriaItemTemplate}
                thumbnail={galleriaThumbnailTemplate}
                fullScreen
                showThumbnails={false}
                activeIndex={galleriaImagesActiveIndex}
                onItemChange={(e) => setGalleriaImagesActiveIndex(e.index)}
                circular
                showItemNavigators
                showThumbnailNavigators={false}
            />
        </>
    );
}

before: when opening the popup, the overlay was not rendered

2025-04-28.10.29.31.mov

after: when opening the popup, the overlay is rendered

12.mov

@melloware melloware merged commit c1680bf into primefaces:master Apr 28, 2025
3 checks passed
@KumJungMin KumJungMin deleted the fix/issue-7450 branch April 29, 2025 11:08
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

Successfully merging this pull request may close these issues.

Galleria: doesn't work correctly if value is set dynamically

2 participants