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(Button): fixing animated label logic #1422

Closed
wants to merge 5 commits into from
Closed

Conversation

VadymBezpalko
Copy link
Contributor

@VadymBezpalko VadymBezpalko commented Nov 4, 2024

Resolves: #1364

Description

Using SCSS variables to pass calculated content width from JS to SCSS, so it will be animated relying only on CSS pseudoclasses.

Storybook

https://feature-1364--613a8e945a5665003a05113b.chromatic.com

Checklist

Obligatory:

  • Self review (use this as your final check for proposed changes before requesting the review)
  • Add correct label
  • Assign pull request with the correct issue

Summary by CodeRabbit

  • New Features

    • Enhanced button interactions with improved hover and focus-visible styles for better visibility.
  • Bug Fixes

    • Streamlined button label animations by removing unnecessary state management, resulting in a more responsive experience.
  • Style

    • Updated SCSS styles for the button component to improve layout and responsiveness during interactions.

Copy link

@vladko-uxds vladko-uxds left a comment

Choose a reason for hiding this comment

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

👍

@VadymBezpalko VadymBezpalko marked this pull request as draft November 28, 2024 08:49
Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes involve modifications to the Button component in Button.tsx, where the state variable isLabelOpen and its associated event handlers have been removed. The label's width is now managed using a CSS variable instead. In the SCSS file, updates include the addition of a max-width property for the button label, ensuring it is hidden by default and only visible on hover or focus. The overall aim is to simplify the component's interaction logic and enhance the visual feedback during user interactions.

Changes

File Change Summary
packages/react-components/src/components/Button/Button.tsx Removed isLabelOpen state and related event handlers; simplified label width management.
packages/react-components/src/components/Button/styles/animated-label.scss Added max-width property for button label; consolidated hover and focus-visible styles.

Assessment against linked issues

Objective Addressed Explanation
Button should not expand automatically (#1364)

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@VadymBezpalko VadymBezpalko marked this pull request as ready for review November 28, 2024 12:04
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

🧹 Outside diff range and nitpick comments (1)
packages/react-components/src/components/Button/styles/animated-label.scss (1)

53-72: Consider DRYing up the hover/focus-visible selectors

The padding adjustments could be consolidated using a shared selector, but the current explicit approach is also valid for maintainability.

  &.#{$base-class}--with-left-icon,
  &.#{$base-class}--with-right-icon {
    padding-right: $padding-default;
    padding-left: $padding-default;
+   &:is(:hover, :focus-visible) {
+     padding-right: $padding-hover-label;
+     padding-left: $padding-hover-icon;
+   }
-   &:hover,
-   &:focus-visible {
-     padding-right: $padding-hover-label;
-     padding-left: $padding-hover-icon;
-   }
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 151a4d8 and 9c6cee3.

📒 Files selected for processing (2)
  • packages/react-components/src/components/Button/Button.tsx (2 hunks)
  • packages/react-components/src/components/Button/styles/animated-label.scss (3 hunks)
🔇 Additional comments (4)
packages/react-components/src/components/Button/styles/animated-label.scss (2)

7-7: Great implementation of CSS-based animation!

The use of CSS variable for width control and inclusion of focus-visible state improves both performance and accessibility.

Also applies to: 10-17


31-31: Perfect fix for the expansion bug!

Setting initial max-width to 0 prevents unwanted expansion, directly addressing issue #1364.

packages/react-components/src/components/Button/Button.tsx (2)

7-7: LGTM! Simplified imports align with CSS-based interaction approach

The removal of keyboard/mouse interaction handlers in favor of CSS pseudoclasses is a good architectural decision.


136-138: Verify button behavior during tab switching

The CSS-based approach should prevent automatic expansion, but please verify:

  1. Button doesn't expand automatically when switching tabs
  2. Label appears only on hover/focus
  3. Animation works smoothly in all scenarios
✅ Verification successful

CSS-based implementation confirmed safe for tab switching

The verification shows:

  • No state-based width control (no useState hooks found)
  • Pure CSS transitions using var(--button-label-width) and max-width
  • Proper hover/focus styles with smooth transitions (200ms cubic-bezier)
  • Clean implementation using CSS variables and pseudoclasses
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining expansion-related code that might interfere
rg -g '!*.{json,md}' -i '(expand|collapse|isLabelOpen)' packages/react-components/src/components/Button/

Length of output: 106


Script:

#!/bin/bash
# Let's check the Button component implementation for any state-based width control
ast-grep --pattern 'const [$_] = useState<$_>($$$)'  packages/react-components/src/components/Button/Button.tsx

# Check for any dynamic width-related styles or classes
rg -g '*.{ts,tsx,css,scss}' '(width|transform|transition)' packages/react-components/src/components/Button/

# Look for any hover/focus related styles
rg -g '*.{ts,tsx,css,scss}' '(:hover|:focus)' packages/react-components/src/components/Button/

Length of output: 6367

Comment on lines +136 to +138
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
{ '--button-label-width': `${labelWidth}px` }
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

Consider adding proper TypeScript types instead of suppressing errors

While the CSS variable implementation is good, using @ts-expect-error is not ideal. Consider adding proper type definitions:

-              // eslint-disable-next-line @typescript-eslint/ban-ts-comment
-              // @ts-expect-error
-              { '--button-label-width': `${labelWidth}px` }
+              { ['--button-label-width' as string]: `${labelWidth}px` }

Or create a proper type:

type CSSProperties = React.CSSProperties & {
  '--button-label-width'?: string;
};

@VadymBezpalko VadymBezpalko removed their assignment Nov 29, 2024
@VadymBezpalko
Copy link
Contributor Author

@marcinsawicki I'm closing this PR because it is not working as expected. You can reopen or duplicate it later.

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.

[Button] - animated button bug
3 participants