-
Notifications
You must be signed in to change notification settings - Fork 390
feat(Modal,Backdrop): Add opt-in animation support #12552
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,41 @@ | ||
| import { css } from '@patternfly/react-styles'; | ||
| import styles from '@patternfly/react-styles/css/components/Backdrop/backdrop'; | ||
| import stylesAnimated from '@patternfly/react-styles/css/components/BackdropAnimations/backdrop-animations'; | ||
| import { useHasAnimations } from '../../helpers'; | ||
|
|
||
| export interface BackdropProps extends React.HTMLProps<HTMLDivElement> { | ||
| /** Content rendered inside the backdrop */ | ||
| children?: React.ReactNode; | ||
| /** Additional classes added to the backdrop */ | ||
| className?: string; | ||
| /** Flag indicating whether animations are enabled. */ | ||
| hasAnimations?: boolean; | ||
| /** Flag to show the backdrop. Used in conjunction with `hasAnimations`. */ | ||
| isVisible?: boolean; | ||
| } | ||
|
|
||
| export const Backdrop: React.FunctionComponent<BackdropProps> = ({ | ||
| children = null, | ||
| className = '', | ||
| hasAnimations: hasAnimationsProp, | ||
| isVisible, | ||
| ...props | ||
| }: BackdropProps) => ( | ||
| <div {...props} className={css(styles.backdrop, className)}> | ||
| {children} | ||
| </div> | ||
| ); | ||
| }: BackdropProps) => { | ||
| const hasAnimations = useHasAnimations(hasAnimationsProp); | ||
|
|
||
| return ( | ||
| <div | ||
| {...props} | ||
| className={css( | ||
| styles.backdrop, | ||
| hasAnimations && stylesAnimated.backdropAnimated, | ||
| hasAnimations && isVisible === true && stylesAnimated.backdropAnimatedVisible, | ||
| hasAnimations && isVisible !== true && stylesAnimated.backdropAnimatedHidden, | ||
| className | ||
| )} | ||
| > | ||
| {children} | ||
| </div> | ||
| ); | ||
| }; | ||
| Backdrop.displayName = 'Backdrop'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { Fragment, useState } from 'react'; | ||
| import { Button, Modal, ModalHeader, ModalBody, ModalFooter, ModalVariant } from '@patternfly/react-core'; | ||
|
|
||
| export const ModalAnimated: React.FunctionComponent = () => { | ||
| const [isModalOpen, setIsModalOpen] = useState(false); | ||
|
|
||
| const handleModalToggle = (_event: KeyboardEvent | React.MouseEvent) => { | ||
| setIsModalOpen((prevIsModalOpen) => !prevIsModalOpen); | ||
| }; | ||
|
|
||
| return ( | ||
| <Fragment> | ||
| <Button variant="primary" onClick={handleModalToggle}> | ||
| Show animated modal | ||
| </Button> | ||
| <Modal | ||
| hasAnimations | ||
| variant={ModalVariant.large} | ||
| isOpen={isModalOpen} | ||
| onClose={handleModalToggle} | ||
| aria-labelledby="modal-animated-label" | ||
| aria-describedby="modal-animated-description" | ||
| elementToFocus="#modal-animated-confirm-button" | ||
| > | ||
| <ModalHeader title="Animated Modal Header" labelId="modal-animated-label" /> | ||
| <ModalBody id="modal-animated-description"> | ||
| Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore | ||
| magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | ||
| consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla | ||
| pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id | ||
| est laborum. | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button id="modal-animated-confirm-button" key="confirm" variant="primary" onClick={handleModalToggle}> | ||
| Confirm | ||
| </Button> | ||
| <Button key="cancel" variant="link" onClick={handleModalToggle}> | ||
| Cancel | ||
| </Button> | ||
| </ModalFooter> | ||
| </Modal> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| </Fragment> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { Fragment, useState } from 'react'; | ||
| import { | ||
| AnimationsProvider, | ||
| Button, | ||
| Modal, | ||
| ModalHeader, | ||
| ModalBody, | ||
| ModalFooter, | ||
| ModalVariant | ||
| } from '@patternfly/react-core'; | ||
|
|
||
| export const ModalAnimatedProvider: React.FunctionComponent = () => { | ||
| const [isModalOpen, setIsModalOpen] = useState(false); | ||
|
|
||
| const handleModalToggle = (_event: KeyboardEvent | React.MouseEvent) => { | ||
| setIsModalOpen((prevIsModalOpen) => !prevIsModalOpen); | ||
| }; | ||
|
|
||
| return ( | ||
| <AnimationsProvider config={{ hasAnimations: true }}> | ||
| <Fragment> | ||
| <Button variant="primary" onClick={handleModalToggle}> | ||
| Show animated modal (via AnimationsProvider) | ||
| </Button> | ||
| <Modal | ||
| variant={ModalVariant.large} | ||
| isOpen={isModalOpen} | ||
| onClose={handleModalToggle} | ||
| aria-labelledby="modal-animated-provider-label" | ||
| aria-describedby="modal-animated-provider-description" | ||
| elementToFocus="#modal-animated-provider-confirm-button" | ||
| > | ||
| <ModalHeader title="Animated Modal Header" labelId="modal-animated-provider-label" /> | ||
| <ModalBody id="modal-animated-provider-description"> | ||
| Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et | ||
| dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex | ||
| ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat | ||
| nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit | ||
| anim id est laborum. | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button | ||
| id="modal-animated-provider-confirm-button" | ||
| key="confirm" | ||
| variant="primary" | ||
| onClick={handleModalToggle} | ||
| > | ||
| Confirm | ||
| </Button> | ||
| <Button key="cancel" variant="link" onClick={handleModalToggle}> | ||
| Cancel | ||
| </Button> | ||
| </ModalFooter> | ||
| </Modal> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| </Fragment> | ||
| </AnimationsProvider> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| .pf-v6-c-backdrop-animated { | ||
| background-color: transparent; | ||
| visibility: hidden; | ||
| pointer-events: none; | ||
| transition: | ||
| background-color 240ms cubic-bezier(0.4, 0.14, 1, 1), /* Carbon equivalent: duration-moderate-02 + motion(exit, expressive) */ | ||
| visibility 0ms linear 240ms; /* Carbon equivalent: duration-moderate-02 */ | ||
| } | ||
|
|
||
| .pf-v6-c-backdrop-animated-visible { | ||
| background-color: var(--pf-v6-c-backdrop--BackgroundColor); | ||
| visibility: visible; | ||
| pointer-events: unset; | ||
| transition: | ||
| background-color 240ms cubic-bezier(0, 0, 0.2, 1), | ||
| visibility 0ms linear 0ms; | ||
| } | ||
|
|
||
| .pf-v6-c-backdrop-animated-hidden { | ||
| background-color: transparent; | ||
| visibility: hidden; | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| @media screen and (prefers-reduced-motion: reduce) { | ||
| .pf-v6-c-backdrop-animated, | ||
| .pf-v6-c-backdrop-animated-visible, | ||
| .pf-v6-c-backdrop-animated-hidden { | ||
| transition: none; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||||||||||||||||||||||||||||||||
| .pf-v6-c-modal-animated { | ||||||||||||||||||||||||||||||||||||||||
| --pf-v6-c-modal-animated--Transition: | ||||||||||||||||||||||||||||||||||||||||
| opacity 240ms cubic-bezier(0.4, 0.14, 1, 1), | ||||||||||||||||||||||||||||||||||||||||
| transform 240ms cubic-bezier(0.4, 0.14, 1, 1), | ||||||||||||||||||||||||||||||||||||||||
| visibility 0ms linear 240ms; | ||||||||||||||||||||||||||||||||||||||||
| opacity: 0; | ||||||||||||||||||||||||||||||||||||||||
| visibility: hidden; | ||||||||||||||||||||||||||||||||||||||||
| pointer-events: none; | ||||||||||||||||||||||||||||||||||||||||
| transform: translate3d(0, -24px, 0); | ||||||||||||||||||||||||||||||||||||||||
| transform-origin: top center; | ||||||||||||||||||||||||||||||||||||||||
| transition: var(--pf-v6-c-modal-animated--Transition); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| .pf-v6-c-modal-animated-open { | ||||||||||||||||||||||||||||||||||||||||
| --pf-v6-c-modal-animated--Transition: | ||||||||||||||||||||||||||||||||||||||||
| transform 240ms cubic-bezier(0, 0, 0.2, 1), | ||||||||||||||||||||||||||||||||||||||||
| visibility 0ms linear 0ms; | ||||||||||||||||||||||||||||||||||||||||
| opacity: 1; | ||||||||||||||||||||||||||||||||||||||||
| visibility: visible; | ||||||||||||||||||||||||||||||||||||||||
| pointer-events: unset; | ||||||||||||||||||||||||||||||||||||||||
| transform: translate3d(0, 0, 0); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Opening animation does not fade in — The open class overrides 🐛 Proposed fix: add opacity to the open transition .pf-v6-c-modal-animated-open {
--pf-v6-c-modal-animated--Transition:
+ opacity 240ms cubic-bezier(0, 0, 0.2, 1),
transform 240ms cubic-bezier(0, 0, 0.2, 1),
visibility 0ms linear 0ms;
opacity: 1;
visibility: visible;
pointer-events: unset;
transform: translate3d(0, 0, 0);
}📝 Committable suggestion
Suggested change
🧰 Tools🪛 Stylelint (17.14.0)[error] 18-18: Expected empty line before declaration (declaration-empty-line-before) (declaration-empty-line-before) 🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deferring this to discuss with PF team during office-hours There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| .pf-v6-c-modal-animated-closed { | ||||||||||||||||||||||||||||||||||||||||
| opacity: 0; | ||||||||||||||||||||||||||||||||||||||||
| visibility: hidden; | ||||||||||||||||||||||||||||||||||||||||
| pointer-events: none; | ||||||||||||||||||||||||||||||||||||||||
| transform: translate3d(0, -24px, 0); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @media screen and (prefers-reduced-motion: reduce) { | ||||||||||||||||||||||||||||||||||||||||
| .pf-v6-c-modal-animated, | ||||||||||||||||||||||||||||||||||||||||
| .pf-v6-c-modal-animated-open, | ||||||||||||||||||||||||||||||||||||||||
| .pf-v6-c-modal-animated-closed { | ||||||||||||||||||||||||||||||||||||||||
| transition: none; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: patternfly/patternfly-react
Length of output: 14629
🏁 Script executed:
Repository: patternfly/patternfly-react
Length of output: 22854
Animated modals still never unmount on close
packages/react-core/src/components/Modal/ModalContent.tsx:82-84With
hasAnimations,ModalContentkeeps rendering afterisOpenbecomesfalse, and there’s no transition-end or timeout path to remove it after the close animation. The modal stays mounted until the parent unmounts it, so the “remove the modal after the closing animation completes” behavior is still missing.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deferring this to discuss with PF team during office-hours