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

feat: enhance search modal with smooth opening and closing transition #3647

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

auraticabhi
Copy link

@auraticabhi auraticabhi commented Feb 4, 2025

Description

  • Added a smooth transition effect for the search modal to improve the user experience.
  • The modal now fades in and scales up when opened and fades out and scales down when closed.
  • Introduced a slight delay before showing the modal to allow for a smooth entry transition.

Related issue(s)
Fixes #3646

Summary by CodeRabbit

  • New Features
    • Enhanced modal dialogs with smooth opening and closing animations.
    • Introduced refined backdrop transitions to elevate the visual experience.

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Walkthrough

The changes add smooth transition animations for the Algolia modal. A new state variable (isVisible) is introduced to control the modal’s opacity and scale during entry and exit. The modal now delays visibility changes using timers, and the close functionality triggers an exit animation before final closure. Additionally, the modal’s backdrop and navigator interactions have been updated to use the new transition-aware flow.

Changes

File Change Summary
components/AlgoliaSearch.tsx Added isVisible state with delayed activation; modified handleClose to include exit animation delay; wrapped DocSearchModal in a backdrop with transition classes; updated onClose prop and navigator to use handleClose.

Assessment against linked issues

Objective Addressed Explanation
Smooth transition animations for modal opening and closing (#3646)

Suggested labels

ready-to-merge

Suggested reviewers

  • derberg
  • magicmatatjahu
  • akshatnema
  • sambhavgupta0705
  • asyncapi-bot-eve
  • Mayaleeeee
  • anshgoyalevil

Poem

I'm a bunny hopping with glee,
Code now flows as smooth as can be.
Modal doors slide in and out with grace,
A gentle dance in the coding space.
Cheers to delays that make UI shine!
🐰✨ Happy hops in every line!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Copy link

netlify bot commented Feb 4, 2025

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 553a4be
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67a1eb090c632100089365b6
😎 Deploy Preview https://deploy-preview-3647--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (326082b) to head (553a4be).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3647   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines          732       732           
=========================================
  Hits           732       732           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 326082b and c039016.

📒 Files selected for processing (1)
  • components/AlgoliaSearch.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 180000ms (2)
  • GitHub Check: Test NodeJS PR - macos-13
  • GitHub Check: Lighthouse CI
🔇 Additional comments (2)
components/AlgoliaSearch.tsx (2)

36-40: LGTM! Interface change is backward compatible.

The updated onClose prop type now correctly handles both programmatic and event-based closures.


127-136: LGTM! Well-structured animation implementation.

The implementation follows best practices:

  • Separate transition durations for backdrop and modal
  • Proper event propagation handling
  • Smooth scale and opacity transitions

components/AlgoliaSearch.tsx Outdated Show resolved Hide resolved
components/AlgoliaSearch.tsx Outdated Show resolved Hide resolved
@auraticabhi auraticabhi changed the title Enhance search modal with smooth opening and closing transition feat: Enhance search modal with smooth opening and closing transition Feb 4, 2025
@auraticabhi auraticabhi changed the title feat: Enhance search modal with smooth opening and closing transition feat: enhance search modal with smooth opening and closing transition Feb 4, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
components/AlgoliaSearch.tsx (1)

129-158: LGTM: Clean transition implementation.

The modal transitions are well-implemented with:

  • Proper backdrop handling
  • Event propagation control
  • Matching transition durations

Consider extracting the transition durations into constants to ensure consistency between timeouts and CSS:

+const ENTRY_DELAY = 10;
+const EXIT_DELAY = 300;
+const BACKDROP_DURATION = 200;
+const MODAL_DURATION = 300;

function AlgoliaModal({ onClose, initialQuery, indexName }: AlgoliaModalProps) {
  // ...
  useEffect(() => {
-   const timer = setTimeout(() => setIsVisible(true), 10);
+   const timer = setTimeout(() => setIsVisible(true), ENTRY_DELAY);
    return () => clearTimeout(timer);
  }, []);

  const handleClose = () => {
    setIsVisible(false);
-   const timer = setTimeout(onClose, 300);
+   const timer = setTimeout(onClose, EXIT_DELAY);
    return () => clearTimeout(timer);
  };

  return createPortal(
    <div
-     className={`fixed inset-0 z-50 bg-black/50 transition-all duration-200 ${
+     className={`fixed inset-0 z-50 bg-black/50 transition-all duration-${BACKDROP_DURATION} ${
        isVisible ? 'scale-100 opacity-100' : 'scale-95 opacity-0'
      }`}
      onClick={handleClose}
    >
      <div
-       className='rounded-lg bg-transparent p-6 shadow-lg transition-all duration-300'
+       className={`rounded-lg bg-transparent p-6 shadow-lg transition-all duration-${MODAL_DURATION}`}
        onClick={(e) => e.stopPropagation()}
      >
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c039016 and a2d6d78.

📒 Files selected for processing (1)
  • components/AlgoliaSearch.tsx (1 hunks)
🧰 Additional context used
🪛 ESLint
components/AlgoliaSearch.tsx

[error] 118-118: Expected blank line after variable declarations.

(newline-after-var)


[error] 119-119: Expected blank line before this statement.

(padding-line-between-statements)


[error] 119-119: Delete ·

(prettier/prettier)


[error] 121-121: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 121-121: Delete ··

(prettier/prettier)


[error] 124-124: Expected blank line after variable declarations.

(newline-after-var)


[error] 125-125: Expected blank line before this statement.

(padding-line-between-statements)


[error] 125-125: Delete ·

(prettier/prettier)

🪛 GitHub Actions: PR testing - if Node project
components/AlgoliaSearch.tsx

[error] 118-118: Expected blank line after variable declarations. newline-after-var


[error] 119-119: Expected blank line before this statement. padding-line-between-statements


[error] 119-119: Delete · prettier/prettier


[error] 121-121: Trailing spaces not allowed. no-trailing-spaces


[error] 121-121: Delete ·· prettier/prettier


[error] 124-124: Expected blank line after variable declarations. newline-after-var


[error] 125-125: Expected blank line before this statement. padding-line-between-statements


[error] 125-125: Delete · prettier/prettier

🔇 Additional comments (1)
components/AlgoliaSearch.tsx (1)

36-40: LGTM: Props type update.

The onClose prop type has been correctly updated to handle the backdrop click event.

components/AlgoliaSearch.tsx Outdated Show resolved Hide resolved
Fixed formatting issues.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
components/AlgoliaSearch.tsx (2)

115-121: Extract delay value as a constant.

Consider extracting the hardcoded delay value as a named constant at the top of the file for better maintainability.

+const MODAL_ENTRY_DELAY_MS = 10;
+
 function AlgoliaModal({ onClose, initialQuery, indexName }: AlgoliaModalProps) {
   const router = useRouter();
   const [isVisible, setIsVisible] = useState(false);
 
   useEffect(() => {
-    const timer = setTimeout(() => setIsVisible(true), 10); // Small delay for smooth entry
+    const timer = setTimeout(() => setIsVisible(true), MODAL_ENTRY_DELAY_MS); // Small delay for smooth entry
 
     return () => clearTimeout(timer); // Cleanup function
   }, []);

123-128: Sync animation duration with CSS transition.

Extract the hardcoded delay value as a constant and ensure it matches the CSS transition duration (200ms for opacity and 300ms for transform).

+const MODAL_EXIT_DELAY_MS = 300; // Match the longest CSS transition duration
+
 function AlgoliaModal({ onClose, initialQuery, indexName }: AlgoliaModalProps) {
   // ...
   const handleClose = () => {
     setIsVisible(false);
-    const timer = setTimeout(onClose, 300); // Delay closing to allow animation to finish
+    const timer = setTimeout(onClose, MODAL_EXIT_DELAY_MS); // Delay closing to allow animation to finish
 
     return () => clearTimeout(timer); // Cleanup function
   };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2d6d78 and 553a4be.

📒 Files selected for processing (1)
  • components/AlgoliaSearch.tsx (1 hunks)

Comment on lines +131 to +160
<div
className={`fixed inset-0 z-50 bg-black/50 transition-all duration-200 ${
isVisible ? 'scale-100 opacity-100' : 'scale-95 opacity-0'
}`}
onClick={handleClose}
>
<div
className='rounded-lg bg-transparent p-6 shadow-lg transition-all duration-300'
onClick={(e) => e.stopPropagation()}
>
<DocSearchModal
initialQuery={initialQuery}
initialScrollY={window.scrollY}
searchParameters={{ distinct: 1 }}
placeholder={indexName === DOCS_INDEX_NAME ? 'Search documentation' : 'Search resources'}
onClose={handleClose}
indexName={indexName}
apiKey={API_KEY}
appId={APP_ID}
navigator={{
navigate({ itemUrl }) {
handleClose();
router.push(itemUrl);
}
}}
hitComponent={Hit}
transformItems={transformItems}
/>
</div>
</div>,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance modal accessibility.

The modal implementation should include proper accessibility features:

  1. Add role="dialog" and aria-modal="true" to the modal wrapper.
  2. Add aria-label to describe the modal's purpose.
  3. Trap focus within the modal when open.
 <div
   className={`fixed inset-0 z-50 bg-black/50 transition-all duration-200 ${
     isVisible ? 'scale-100 opacity-100' : 'scale-95 opacity-0'
   }`}
+  role="dialog"
+  aria-modal="true"
+  aria-label="Search documentation"
   onClick={handleClose}
 >

Consider using a focus trap library like focus-trap-react to manage keyboard focus:

import { FocusTrap } from 'focus-trap-react';

// Wrap modal content
<FocusTrap active={isVisible}>
  <div className="rounded-lg bg-transparent p-6 shadow-lg transition-all duration-300">
    {/* ... */}
  </div>
</FocusTrap>

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.

[FEATURE] Add smooth transition to the search modal opening
1 participant