Navigation Menu

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

Adding isValidProp to MotionConfig #1410

Merged
merged 4 commits into from Jan 12, 2022
Merged

Conversation

mattgperry
Copy link
Collaborator

This PR adds an isValidProp prop to MotionConfig that allows the external injection of an isValidProp function.

Fixes #1406

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 7, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8e7667a:

Sandbox Source
Framer Motion: Simple animation Configuration
App Store UI using React and Framer Motion Configuration
Framer Motion: Reorder animation Configuration
Framer Motion: growing item positionTransition issue Configuration
Framer Motion: Image lightbox Configuration


const { container } = render(<Component />)

expect(container.firstChild).not.toHaveAttribute("data-foo")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also test that a valid attribute is forwarded to the DOM?

@@ -3,6 +3,16 @@ import { isValidMotionProp } from "../../../motion/utils/valid-prop"

let shouldForward = (key: string) => !isValidMotionProp(key)

export type IsValidProp = (key: string) => boolean

export function loadExternalIsValidProp(emotionIsPropValid?: IsValidProp) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still call it emotionIsPropValid if it could be a user-provided function?


// Handle events explicitly as Emotion validates them all as true
shouldForward = (key: string) =>
key.startsWith("on") ? !isValidMotionProp(key) : emotionIsPropValid(key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's an injected isValidProp provided by MotionConfig, wouldn't it be hijacked by isValidMotionProp? For example, isValidProp={key => key !== "onStart"}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that might have to be a limitation of the API that our events are always consumed

@mattgperry
Copy link
Collaborator Author

@shuangq Great comments, I've just pushed some changes

Copy link
Contributor

@shuangq shuangq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👏

@mattgperry mattgperry added the automerge Land this PR label Jan 12, 2022
@mergetron mergetron bot merged commit 4f2b596 into main Jan 12, 2022
@mergetron mergetron bot deleted the feature/inject-is-valid-prop branch January 12, 2022 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Land this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Prevent props from passing through to DOM elements
2 participants