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: Added focus ring for focus visible #37700

Merged
merged 24 commits into from
Jan 13, 2025
Merged

Conversation

albinAppsmith
Copy link
Collaborator

@albinAppsmith albinAppsmith commented Nov 26, 2024

Description

This PR adds focus ring for CTA's in the platform.

Fixes #37699

Automation

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

🔍 Cypress test results

Tip

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


Mon, 13 Jan 2025 08:19:28 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced focus state styling for the select component, improving visibility when active.
    • Updated focus management for buttons, inputs, and various components to utilize :focus-visible, enhancing accessibility.
    • Refined keyboard navigation and interaction logic for the color picker component.
    • Introduced new props for conditional focus styling in the editor and button components.
    • Added support for AI assistance features in the code editor.
    • Improved focus ring visibility in the segmented control and switch components.
  • Bug Fixes

    • Improved accessibility and visual clarity of focus outlines across the application.
  • Chores

    • Removed outdated focus outline rules, allowing for a more streamlined styling approach.

Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

Walkthrough

The pull request introduces several modifications to the CSS styles for the .ads-v2-select component and related styles. Key changes include adjustments to the outline-offset property, updates to CSS variables for outline properties, and the introduction of new styles for focus states. Additionally, some rules disabling focus outlines have been removed, allowing for improved visibility and clarity during user interactions. The overall structure of the CSS remains intact, focusing on enhancing accessibility and visual feedback for focused elements.

Changes

File Path Change Summary
app/client/packages/design-system/ads/src/Select/styles.css - Modified outline-offset from variable to -2px in .ads-v2-select.rc-select-focused.
- Removed --select-color-border in the same class.
- Added border-color: transparent in .ads-v2-select.rc-select-focused > .rc-select-selector.
app/client/packages/design-system/ads/src/__theme__/default/index.css - Updated CSS variables for outline properties:
--ads-v2-color-outline to var(--ads-v2-color-blue-300),
--ads-v2-border-width-outline to 2px,
--ads-v2-offset-outline to -2px.
- Added :focus selector to remove default outlines.
- Updated .ads-v2-focus-ring class with new outline styles.
app/client/src/index.css - Removed rules disabling outlines for focused elements, including the .ads-v2-select.rc-select-focused.
app/client/packages/design-system/ads-old/src/SearchComponent/index.tsx - Updated focus styling in SearchInputWrapper to use :focus-visible instead of :focus.
app/client/packages/design-system/ads/src/Button/Button.styles.tsx - Added isFocusVisible prop to StyledButton for conditional focus styling.
app/client/packages/design-system/ads/src/Button/Button.tsx - Introduced useFocusRing for focus management and updated click handling logic.
app/client/packages/design-system/ads/src/Input/Input.styles.tsx - Removed focus and active state styles from StyledInput, applying styles based on isFocusVisible.
app/client/packages/design-system/ads/src/Input/Input.tsx - Added useCallback for handleOnChange and updated useFocusRing.
app/client/packages/design-system/ads/src/Text/Text.styles.tsx - Changed focus handling in StyledEditableInput to use :focus-visible.
app/client/src/components/editorComponents/CodeEditor/styledComponents.ts - Renamed :focus to :focus-visible in EditorWrapper.
app/client/src/components/propertyControls/ColorPickerComponentV2.tsx - Updated focus handling in StyledInputGroup to use :focus-visible.
app/client/src/components/propertyControls/IconSelectControl.tsx - Changed focus handling for StyledButton to :focus-visible.
app/client/src/components/propertyControls/IconSelectControlV2.tsx - Updated focus handling for StyledButton to :focus-visible.

Possibly related PRs

  • feat: Anvil: Interact with a focused widget's widget name component #33646: The changes in the main PR regarding focus state styling in the .ads-v2-select component may relate to the modifications in the AnvilWidgetName component, which also involves focus management and user interactions.
  • chore: refactor inputs #36680: The refactor of input components in this PR may connect to the changes in the main PR, as both involve updates to styling and behavior of input elements, particularly in handling focus and visual representation.
  • fix: Focus retention on inputs #36770: This PR focuses on fixing focus retention in inputs, which aligns with the main PR's emphasis on enhancing focus state styling for the .ads-v2-select component.

Suggested labels

UI Improvement, skip-changelog

Suggested reviewers

  • ankitakinger
  • sagar-qa007

🎉 In the land of CSS, where styles do play,
Focus outlines now shine, brightening the way.
With colors and borders, so clear and so bold,
User interactions, a sight to behold!
A sprinkle of changes, a dash of delight,
In the world of design, everything feels right! ✨


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.

@github-actions github-actions bot added IDE Navigation Issues/feature requests related to IDE navigation, and context switching IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Task A simple Todo labels Nov 26, 2024
@albinAppsmith
Copy link
Collaborator Author

/build-deploy-preview skip-test=true

@github-actions github-actions bot added the Enhancement New feature or request label Nov 26, 2024
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12025302772.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 37700.
recreate: .

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)
app/client/packages/design-system/ads/src/__theme__/default/index.css (1)

242-244: LGTM! Consider documenting the focus ring variables.

The focus ring variables follow accessibility best practices. However, there's a TODO comment about focus issues across the platform.

Consider adding a comment block explaining the purpose and usage of these focus ring variables for better maintainability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1295c6a and f303d56.

📒 Files selected for processing (3)
  • app/client/packages/design-system/ads/src/Select/styles.css (2 hunks)
  • app/client/packages/design-system/ads/src/__theme__/default/index.css (2 hunks)
  • app/client/src/index.css (0 hunks)
💤 Files with no reviewable changes (1)
  • app/client/src/index.css
🔇 Additional comments (3)
app/client/packages/design-system/ads/src/Select/styles.css (2)

53-53: LGTM: Focus ring offset implementation

The fixed -2px offset provides consistent focus indication across browsers, improving accessibility for keyboard users.


115-117: LGTM: Clean focus state implementation

Setting transparent border prevents double-border effect while maintaining the focus ring visibility. This is a good practice for accessible focus states.

app/client/packages/design-system/ads/src/__theme__/default/index.css (1)

255-258: LGTM! Verify browser compatibility for :focus-visible.

The focus ring implementation follows modern accessibility patterns. The use of !important is appropriate here to prevent focus ring suppression.

Let's verify browser support for the :focus-visible pseudo-class:

✅ Verification successful

Focus ring implementation is compatible with modern browsers

The codebase shows consistent focus ring implementation across components using :focus-visible with fallback .ads-v2-focus-ring class. The styles are properly scoped and use CSS custom properties for consistent theming.

Key findings from the codebase scan:

  • :focus-visible is used consistently in design system components
  • Proper outline styles with !important to prevent overrides
  • CSS custom properties for outline width, color and offset
  • No conflicting browser-specific focus styles found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any browser-specific focus styles in the codebase
# that might conflict with the new implementation

# Search for any existing focus-related styles
rg -g '*.css' -i '(:focus|focus-|outline:)'

# Search for browser-specific focus style overrides
rg -g '*.css' -i '(-moz-|webkit-|ms-).*(focus|outline)'

Length of output: 125880

@@ -50,8 +50,7 @@
/* Focused */
.ads-v2-select.rc-select-focused {
outline: var(--ads-v2-border-width-outline) solid var(--ads-v2-color-outline);
outline-offset: var(--ads-v2-offset-outline);
--select-color-border: var(--ads-v2-colors-control-field-active-border);
outline-offset: -2px;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Focus ring contrast needs improvement

The current focus ring uses --ads-v2-color-blue-300: #8bb0fa which may not provide sufficient contrast against light backgrounds like #fff used in the Select component. Consider using a darker blue shade (e.g., --ads-v2-color-blue-600: #2d6bf4) for better accessibility compliance.

  • app/client/packages/design-system/ads/src/__theme__/default/index.css: Update --ads-v2-color-outline to use a higher contrast color
  • app/client/packages/design-system/ads/src/Select/rc-styles.css: Multiple background colors (#fff, #ddd) need to be tested against the focus ring
🔗 Analysis chain

Verify focus ring contrast ratio

Please ensure the focus ring color (var(--ads-v2-color-outline)) provides sufficient contrast against all possible background colors for accessibility compliance.

Also applies to: 115-117

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the definition of --ads-v2-color-outline to verify contrast
rg --type css "ads-v2-color-outline|ads-v2-color-blue-300" -A 2

Length of output: 2365


Script:

#!/bin/bash
# Search for background colors that might be used with the focus ring
rg --type css "background|bg-color" app/client/packages/design-system/ads/src/Select/

Length of output: 1031


Script:

#!/bin/bash
# Search for color definitions in theme files to analyze contrast
rg --type css "color:|background-color:|bg-color:" app/client/packages/design-system/ads/src/__theme__/default/

Length of output: 1103


Script:

#!/bin/bash
# Check if there are any dark theme definitions
fd -e css -e ts -e js "dark" app/client/packages/design-system/ads/src/__theme__/

Length of output: 81

@albinAppsmith
Copy link
Collaborator Author

/build-deploy-preview skip-test=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12027252268.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 37700.
recreate: .

@albinAppsmith
Copy link
Collaborator Author

/build-deploy-preview skip-test=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12035598494.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 37700.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-37700.dp.appsmith.com

outline: var(--ads-v2-border-width-outline) solid var(--ads-v2-color-outline);
outline-offset: var(--ads-v2-offset-outline);
.ads-v2-focus-ring,
:focus-visible {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we know exactly where we should apply styles? Can we use more specific selectors?

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Dec 13, 2024
@albinAppsmith albinAppsmith requested a review from a team as a code owner December 16, 2024 16:34
@albinAppsmith albinAppsmith added the ok-to-test Required label for CI label Dec 16, 2024
@albinAppsmith
Copy link
Collaborator Author

/build-deploy-preview skip-test=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12357100341.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 37700.
recreate: .

css`
outline: var(--ads-v2-border-width-outline) solid
var(--ads-v2-color-outline) !important;
outline-offset: var(--ads-v2-offset-outline) !important;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why we need !important here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some how this is conflicting with focus. I have added a different fix but that also look little confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

when i disable :focus outline, it affecting :focus-visible also

box-sizing: border-box;
width: 100%;

input:focus-visible {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I understand, here we should also use focus and not focus-visible, right?

outline-offset: var(--ads-v2-offset-outline);
}
${({ isFocusVisible }) =>
isFocusVisible &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is only focus-visible needed for the button?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah we don need focus styles right

@@ -1794,6 +1794,7 @@ class CodeEditor extends Component<Props, State> {
onMouseOver={this.handleMouseMove}
ref={this.editorWrapperRef}
removeHoverAndFocusStyle={this.props?.removeHoverAndFocusStyle}
showFocusRing={!this.props.isJSObject}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we disabling focus ring for isJSObject? Why can't we implement it here?

I would also suggest using a different name for the prop, since the focusRing is name of hook from Spectrum and we can start using something else tomorrow. Let's call it showFocusVisible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is JsObject editor. Showing a focus ring for entire editor doesn't look good.

/**
Disable outline completely from all components
*/
:focus,
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jsartisan You have to see this!

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we cant escape till we remove blueprint components component. This is done because of blueprint CSS from what I know.

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Dec 30, 2024
Copy link

github-actions bot commented Jan 8, 2025

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Jan 8, 2025
@albinAppsmith albinAppsmith reopened this Jan 13, 2025
@albinAppsmith
Copy link
Collaborator Author

/build-deploy-preview skip-test=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12742095072.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 37700.
recreate: .

@albinAppsmith
Copy link
Collaborator Author

/ok-to-test

Copy link

Whoops! Looks like you're using an outdated method of running the Cypress suite.
Please check this doc to learn how to correct this!

Copy link

Deploy-Preview-URL: https://ce-37700.dp.appsmith.com

@albinAppsmith
Copy link
Collaborator Author

/build-deploy-preview skip-test=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12742461505.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 37700.
recreate: .

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/design-system/ads/src/Link/Link.styles.tsx (1)

94-95: Consider documenting the CSS custom properties.

While the implementation is solid, it would be helpful to add JSDoc comments describing the expected values for --ads-v2-color-outline and --ads-v2-offset-outline variables.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between be0c6b4 and 2597087.

📒 Files selected for processing (1)
  • app/client/packages/design-system/ads/src/Link/Link.styles.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
🔇 Additional comments (1)
app/client/packages/design-system/ads/src/Link/Link.styles.tsx (1)

94-95: LGTM! Focus ring implementation aligns with accessibility best practices.

The addition of !important flags ensures the focus outline styles aren't overridden, which is crucial for maintaining keyboard navigation accessibility.

@albinAppsmith
Copy link
Collaborator Author

/build-deploy-preview skip-test=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12742973071.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 37700.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-37700.dp.appsmith.com

@albinAppsmith albinAppsmith merged commit dd5a6d6 into release Jan 13, 2025
53 checks passed
@albinAppsmith albinAppsmith deleted the ads-v2/focus-ring branch January 13, 2025 09:13
hetunandu added a commit that referenced this pull request Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request IDE Navigation Issues/feature requests related to IDE navigation, and context switching IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product ok-to-test Required label for CI Stale Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] - Add focus ring to platform
3 participants