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

fix(calendar): rtl navigation #4565

Open
wants to merge 6 commits into
base: canary
Choose a base branch
from

Conversation

MarufSharifi
Copy link

@MarufSharifi MarufSharifi commented Jan 15, 2025

Closes #4541

📝 Description

Fixed the reverse behavior of calendar navigation in a RTL Layout.

⛳️ Current behavior (updates)

Reversed Next and Previous Button Behavior in Persian Locale (fa) with Calendar

🚀 New behavior

Fixed the reverse Next and Previous button behavior in RTL Calendar

💣 Is this a breaking change (Yes/No):

📝 Additional Information

Summary by CodeRabbit

  • New Features

    • Added localization support for text direction in the calendar component.
    • Implemented dynamic button rendering based on locale (LTR/RTL).
  • Bug Fixes

    • Resolved navigation issues with the next and previous buttons in right-to-left (RTL) layouts, ensuring consistent functionality across various locales.
  • Accessibility

    • Improved international user experience by adapting calendar layout to different text directions.

Copy link

changeset-bot bot commented Jan 15, 2025

🦋 Changeset detected

Latest commit: 63fff5c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@heroui/calendar Patch
@heroui/date-picker Patch
@heroui/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 15, 2025

@MarufSharifi is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Walkthrough

The pull request introduces localization support to the CalendarBase component by integrating the useLocale hook from @react-aria/i18n. This change enables the component to determine text direction based on the current locale, specifically handling left-to-right (LTR) and right-to-left (RTL) layouts. The implementation dynamically adjusts the navigation button behavior and props to ensure consistent month navigation across different language contexts.

Changes

File Change Summary
packages/components/calendar/src/calendar-base.tsx - Added useLocale hook import
- Introduced localeDirection variable
- Created isRTL boolean to check text direction
- Conditionally assigned button props based on locale direction
.changeset/cyan-deers-tap.md - Applied patch to @heroui/calendar for navigation button behavior in RTL layouts
packages/components/calendar/src/use-calendar-base.ts - Added direction property from useLocale hook
- Introduced isRTL constant to check direction
- Updated slots object to include isRTL property
packages/core/theme/src/components/calendar.ts - Added new variant isRTL to calendar configuration
- Updated default variant isRTL: false

Assessment against linked issues

Objective Addressed Explanation
Fix reversed button behavior in Persian locale
Ensure consistent navigation across RTL/LTR layouts

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 681b6b4 and 63fff5c.

📒 Files selected for processing (3)
  • packages/components/calendar/src/calendar-base.tsx (3 hunks)
  • packages/components/calendar/src/use-calendar-base.ts (2 hunks)
  • packages/core/theme/src/components/calendar.ts (1 hunks)
🔇 Additional comments (7)
packages/components/calendar/src/use-calendar-base.ts (2)

191-193: LGTM! Clean implementation of RTL detection.

The implementation correctly uses the useLocale hook to determine text direction and sets up the isRTL flag.


266-266: LGTM! Proper integration with slots configuration.

The isRTL flag is correctly passed to the calendar slots configuration.

packages/core/theme/src/components/calendar.ts (2)

151-157: LGTM! Well-structured RTL variant implementation.

The RTL variant is properly implemented with correct button ordering for RTL layouts.


164-164: LGTM! Appropriate default value.

Setting isRTL: false as default ensures backward compatibility.

packages/components/calendar/src/calendar-base.tsx (3)

74-75: LGTM! Clean RTL detection implementation.

The implementation correctly extracts the locale direction and sets up the isRTL flag.

Also applies to: 81-82


90-93: LGTM! Proper button props swapping for RTL.

The implementation correctly swaps the button props and their respective onPress handlers based on the RTL direction. This ensures that the navigation buttons work as expected in both LTR and RTL layouts.

Also applies to: 106-109


Line range hint 74-109: Verify RTL support for Persian locale.

The implementation looks correct, but let's verify that we have proper RTL support for the Persian locale.

✅ Verification successful

RTL support for Persian locale is properly implemented

The implementation correctly handles RTL for Persian and other RTL locales by:

  • Using the locale-agnostic direction from useLocale
  • Consistently applying RTL transformations
  • Following the established RTL patterns used across other components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for Persian locale support and RTL-related code

# Check for Persian locale support
rg -l "fa(-|_)[A-Z]{2}" .

# Check for RTL-related code and Persian locale handling
rg "direction.*=.*rtl|locale.*=.*fa"

# Check for any hardcoded RTL-specific styles that might conflict
rg "rtl:|direction:"

Length of output: 3475

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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
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: 0

🧹 Nitpick comments (1)
packages/components/calendar/src/calendar-base.tsx (1)

66-66: Fix typo in variable name.

The variable name isLRT contains a typo and should be isLTR (Left-To-Right).

-  const isLRT = localeDirection === "ltr";
+  const isLTR = localeDirection === "ltr";
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 992220a and 20a888e.

📒 Files selected for processing (1)
  • packages/components/calendar/src/calendar-base.tsx (3 hunks)
🔇 Additional comments (2)
packages/components/calendar/src/calendar-base.tsx (2)

12-12: LGTM! Good choice of i18n hook.

The addition of useLocale from @react-aria/i18n is appropriate for implementing RTL support.


75-81: Well-implemented RTL navigation logic!

The implementation correctly handles:

  • Button behavior swapping for RTL mode
  • Visual ordering through CSS classes
  • Animation direction preservation
  • Accessibility through ARIA props

However, let's verify the RTL behavior across different locales:

Also applies to: 94-100

@MarufSharifi MarufSharifi force-pushed the fix/calendar-rtl-navigation branch from 20a888e to 26b2921 Compare January 16, 2025 03:25
Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

please add changeset

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: 0

🧹 Nitpick comments (1)
.changeset/cyan-deers-tap.md (1)

5-5: Consider enhancing the changeset description.

While the current description is clear, consider adding:

  • Which RTL locales were tested (e.g., Persian/fa)
  • Confirmation that LTR layouts remain unaffected
  • Any testing steps or scenarios verified
-Fixed reversed navigation behavior of nextButton and prevButton in the RTL calendar. The buttons now correctly navigate to the next and previous months, ensuring consistent behavior across all locales and layouts. (#4541)
+Fixed reversed navigation behavior of nextButton and prevButton in the RTL calendar, particularly affecting Persian (fa) locale. The buttons now correctly navigate to the next and previous months, ensuring consistent behavior across RTL layouts while maintaining existing LTR functionality. Tested with Persian and Arabic locales. (#4541)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 26b2921 and 7e99792.

📒 Files selected for processing (1)
  • .changeset/cyan-deers-tap.md (1 hunks)
🔇 Additional comments (1)
.changeset/cyan-deers-tap.md (1)

1-3: LGTM! Version bump is appropriate.

The patch version bump is correct for this bug fix, following semantic versioning principles.

@MarufSharifi
Copy link
Author

@wingkwong changeset added

@wingkwong wingkwong added this to the v2.6.15 milestone Jan 21, 2025
Copy link

vercel bot commented Jan 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
heroui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 25, 2025 5:31am
heroui-sb 🛑 Canceled (Inspect) Jan 25, 2025 5:31am

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

The changes involves a lot of ternary operators. Please make it cleaner.

packages/components/calendar/src/calendar-base.tsx Outdated Show resolved Hide resolved
packages/components/calendar/src/calendar-base.tsx Outdated Show resolved Hide resolved
packages/components/calendar/src/calendar-base.tsx Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reversed Next and Previous Button Behavior in Persian Locale (fa) with NextUI Calendar
2 participants