Skip to content

chore: shift the chat button when scrollbar shows#39559

Merged
jsartisan merged 2 commits intoreleasefrom
chore/shift-suffix-on-scrollbar
Mar 5, 2025
Merged

chore: shift the chat button when scrollbar shows#39559
jsartisan merged 2 commits intoreleasefrom
chore/shift-suffix-on-scrollbar

Conversation

@jsartisan
Copy link
Contributor

@jsartisan jsartisan commented Mar 5, 2025

CleanShot.2025-03-04.at.22.19.22.mp4

/ok-to-test tags="@tag.Anvil"

Summary by CodeRabbit

  • New Features

    • Introduced dynamic scrollbar width styling that enhances the overall theme layout.
    • Input and textarea components now automatically detect and adjust based on scrollbar presence.
    • Made available a new utility for accurately measuring scrollbar width.
  • Style

    • Applied new CSS rules to ensure proper positioning of suffix elements in input groups when scrollbars appear.

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13673799093
Commit: a72538b
Cypress dashboard.
Tags: @tag.Anvil
Spec:


Wed, 05 Mar 2025 10:49:39 UTC

@jsartisan jsartisan requested review from a team and KelvinOm as code owners March 5, 2025 05:44
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

Walkthrough

This PR enhances the design system by introducing dynamic scrollbar width support. A new utility function computes the scrollbar width, which is then memoized in the useCssTokens hook as a CSS custom property. The ThemeProvider component integrates this property into its rendered class names. Additionally, input components now adjust their layout via updated CSS rules and logic in the TextArea component, which conditionally sets an attribute based on the element’s scroll metrics. Export updates ensure the new functionality is accessible throughout the application.

Changes

File(s) Change Summary
app/client/packages/design-system/theming/src/hooks/.../useCssTokens.tsx
app/client/packages/design-system/theming/src/theme/.../ThemeProvider.tsx
Added a new CSS custom property (--scrollbar-width) computed via a new utility. The hook memoizes this value and the provider integrates it into the component's class name.
app/client/packages/design-system/widgets/src/components/Input/.../styles.module.css
app/client/packages/design-system/widgets/src/components/TextArea/.../TextArea.tsx
Introduced a CSS rule and component logic to adjust layout. The TextArea now checks if content overflows and sets or removes the data-has-scrollbar attribute accordingly.
app/client/packages/utils/src/dom/getScrollbarWidth.ts
app/client/packages/utils/src/dom/index.ts
app/client/packages/utils/src/index.ts
Added a new utility function to measure scrollbar width and updated exports to expose this functionality across the project.

Sequence Diagram(s)

sequenceDiagram
    participant TP as ThemeProvider
    participant H as useCssTokens Hook
    participant G as getScrollbarWidth
    TP->>H: Call useCssTokens(theme)
    H->>G: Compute scrollbar width
    G-->>H: Return width value
    H-->>TP: Return CSS class with --scrollbar-width property
    TP->>DOM: Render component with updated className
Loading
sequenceDiagram
    participant TA as TextArea Component
    participant IE as Input Element
    TA->>IE: Adjust height based on content
    IE-->>TA: Provide clientHeight and scrollHeight
    alt scrollHeight > clientHeight
      TA->>IE: Set data-has-scrollbar = "true"
    else 
      TA->>IE: Remove data-has-scrollbar attribute
    end
Loading

Possibly related PRs

  • fix: add ResizeObserver to change textarea height based on width changes #38011: The changes in the main PR are related to the modifications in the TextArea component in the retrieved PR, as both involve enhancements to the handling of scrollbar width and dynamic styling in text input components.
  • chore: fix text area ui bug #38282: The changes in the main PR are related to the modifications in the styles.module.css file, specifically regarding the handling of scrollbar-related styles, which connects to the adjustments made in the retrieved PR for the input components.
  • chore: refactor inputs #36680: The changes in the main PR, specifically the introduction of the scrollbarWidthClassName variable in the useCssTokens hook, are directly related to the modifications in the ThemeProvider component, which utilizes this variable, indicating a strong connection at the code level.

Suggested labels

ok-to-test, Enhancement, Bug, IDE Product, Task

Suggested reviewers

  • KelvinOm
  • ankitakinger

Poem

In our code, a new twist unfurls,
Scrollbars measured with dynamic swirls.
Hooks and themes now dance in sync,
Input fields adjust in a blink.
Cheers to change, on the design brink!
🎉🌟


📜 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 09f4a77 and a72538b.

📒 Files selected for processing (1)
  • app/client/packages/design-system/widgets/src/components/TextArea/src/TextArea.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/packages/design-system/widgets/src/components/TextArea/src/TextArea.tsx
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
  • GitHub Check: client-lint / client-lint
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Mar 5, 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: 0

🧹 Nitpick comments (1)
app/client/packages/utils/src/dom/getScrollbarWidth.ts (1)

1-15: Consider memoizing the scrollbar width calculation.

The function creates and destroys DOM elements on each call, which is inefficient if called frequently. Scrollbar width rarely changes during a session.

-export const getScrollbarWidth = () => {
+export const getScrollbarWidth = (() => {
+  let width: number | null = null;
+  
+  return () => {
+    if (width !== null) return width;
+    
+    // Only calculate if we're in a browser environment
+    if (typeof document === 'undefined') return 0;
+    
     const scrollDiv = document.createElement("div");
 
     scrollDiv.setAttribute(
       "style",
       "width: 100px; height: 100px; overflow: scroll; position:absolute; top:-9999px;",
     );
     document.body.appendChild(scrollDiv);
 
     const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
 
     document.body.removeChild(scrollDiv);
 
-    return scrollbarWidth;
+    width = scrollbarWidth;
+    return width;
+  };
 };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 320b168 and 09f4a77.

📒 Files selected for processing (7)
  • app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx (2 hunks)
  • app/client/packages/design-system/theming/src/theme/src/ThemeProvider.tsx (2 hunks)
  • app/client/packages/design-system/widgets/src/components/Input/src/styles.module.css (1 hunks)
  • app/client/packages/design-system/widgets/src/components/TextArea/src/TextArea.tsx (1 hunks)
  • app/client/packages/utils/src/dom/getScrollbarWidth.ts (1 hunks)
  • app/client/packages/utils/src/dom/index.ts (1 hunks)
  • app/client/packages/utils/src/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/client/packages/utils/src/dom/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
🔇 Additional comments (8)
app/client/packages/utils/src/index.ts (1)

6-6: New DOM utility export looks good.

The export statement correctly exposes the DOM utility functions, maintaining consistent structure with other exports.

app/client/packages/design-system/theming/src/theme/src/ThemeProvider.tsx (2)

22-22: Correctly added scrollbarWidth token.

The new scrollbarWidthClassName is properly included in the destructuring from useCssTokens.


36-36: Properly applied scrollbarWidth class.

The new scrollbarWidthClassName is correctly incorporated into the className composition.

app/client/packages/design-system/widgets/src/components/Input/src/styles.module.css (1)

59-62:

Details

✅ Verification successful

CSS fix for suffix positioning with scrollbar present.

This rule correctly adjusts the suffix element's position when a scrollbar appears in a textarea, accomplishing the PR objective.


🏁 Script executed:

#!/bin/bash
# Check if this data-has-scrollbar attribute is set somewhere in the codebase

# Use AST-grep to locate where this attribute might be set
ast-grep --pattern $'[data-has-scrollbar]' || echo "No direct attribute references found"

# Check for more implementation details using ripgrep
rg -l "data-has-scrollbar" || echo "No string matches found"

# Look for JavaScript/TypeScript code that might be setting this attribute
rg -l "setAttr.*has-scrollbar|setAttribute.*has-scrollbar" --type ts --type tsx || echo "No attribute setting code found"

Length of output: 572


CSS suffix adjustment with scrollbar verified

The CSS rule in app/client/packages/design-system/widgets/src/components/Input/src/styles.module.css (lines 59-62) has been verified. The output confirms that the [data-has-scrollbar] attribute is correctly referenced in the CSS file, and its usage in the TextArea component (app/client/packages/design-system/widgets/src/components/TextArea/src/TextArea.tsx) validates that the rule is applied as intended. This ensures the suffix element is properly repositioned when a scrollbar appears in a textarea.

app/client/packages/design-system/widgets/src/components/TextArea/src/TextArea.tsx (1)

80-84: Appropriate handling for scrollbar detection.

The implementation correctly detects when a textarea has a scrollbar by comparing scrollHeight against clientHeight, and appropriately sets a data attribute that can be used for styling adjustments.

app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx (3)

8-8: LGTM: Clean import addition.

Import added correctly for the new functionality.


95-99: Efficient implementation for scrollbar width detection.

Good use of useMemo to create the CSS class with scrollbar width. The empty dependency array ensures this is only calculated once, which is appropriate since scrollbar width doesn't change during runtime.


107-107: Effective export of the new functionality.

Properly exports the new className for use by consumers of this hook.

setTextFieldHeight(height + marginTop + marginBottom);

input.style.height = `${input.scrollHeight}px`;
input.style.height = `${input.scrollHeight + 1}px`;
Copy link
Contributor Author

@jsartisan jsartisan Mar 5, 2025

Choose a reason for hiding this comment

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

had to add 1px here, there was a weird scrollbar bug happening without it.

CleanShot.2025-03-05.at.12.28.44.mp4

@jsartisan jsartisan added the ok-to-test Required label for CI label Mar 5, 2025
@jsartisan jsartisan merged commit 1d60545 into release Mar 5, 2025
59 checks passed
@jsartisan jsartisan deleted the chore/shift-suffix-on-scrollbar branch March 5, 2025 11:04
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Apr 12, 2025
https://github.com/user-attachments/assets/efccee4b-c329-4766-8fc6-92c8a135f8df

/ok-to-test tags="@tag.Anvil"

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced dynamic scrollbar width styling that enhances the overall
theme layout.
- Input and textarea components now automatically detect and adjust
based on scrollbar presence.
- Made available a new utility for accurately measuring scrollbar width.

- **Style**
- Applied new CSS rules to ensure proper positioning of suffix elements
in input groups when scrollbars appear.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13673799093>
> Commit: a72538b
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13673799093&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Anvil`
> Spec:
> <hr>Wed, 05 Mar 2025 10:49:39 UTC
<!-- end of auto-generated comment: Cypress test results  -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants