Skip to content

Conversation

amje
Copy link
Contributor

@amje amje commented Jul 14, 2025

Summary by Sourcery

Fix text alignment issues in Checkbox, Radio, Switch, and ControlLabel components by refining CSS styles and layout rules.

Bug Fixes:

  • Remove hidden non-breaking space pseudo-elements and inline-block hacks from indicators to correct label misalignment
  • Align ControlLabel text and indicator baseline to ensure consistent vertical alignment

Enhancements:

  • Unify control positioning using the inset shorthand and reset background/border for input controls
  • Add outline-offset to focus-visible states for clearer focus styling
  • Convert indicators to flex containers with centered alignment for consistent spacing

Copy link
Contributor

sourcery-ai bot commented Jul 14, 2025

Reviewer's Guide

This PR refactors the styling of Checkbox, Radio, Switch, and ControlLabel components by streamlining indicator CSS, consolidating control positioning with the inset shorthand, adding focus outline offsets, and adjusting label alignment to correct text placement.

Class diagram for updated component structure and styling

classDiagram
    class Checkbox {
        +__indicator: position: relative
        +__control: position: absolute; inset: 0; opacity: 0
        +__control:focus-visible + __outline: outline-offset: 1px
    }
    class Radio {
        +__indicator: position: relative
        +__control: position: absolute; inset: 0; opacity: 0
        +__control:focus-visible + __outline: outline-offset: 1px
        +__disc: inset by size, background-color on checked
    }
    class Switch {
        +__indicator: position: relative
        +__control: position: absolute; inset: 0; opacity: 0
        +__control:focus-visible + __outline: outline-offset: 1px
    }
    class ControlLabel {
        +display: inline-flex
        +align-items: baseline
        +__indicator: display: flex; align-items: center; justify-content: center
        +__indicator::after: content: '\00a0'; visibility: hidden
    }
    Checkbox --|> ControlLabel : label wraps indicator
    Radio --|> ControlLabel : label wraps indicator
    Switch --|> ControlLabel : label wraps indicator
Loading

File-Level Changes

Change Details Files
Streamline indicator styling across Checkbox, Radio, and Switch
  • Removed display:inline-block from the indicator elements
  • Deleted the hidden ::after pseudo-element used for spacing
  • Removed inherited cursor rules on indicators
src/components/Radio/Radio.scss
src/components/Switch/Switch.scss
src/components/Checkbox/Checkbox.scss
Unify control positioning and reset default styles
  • Replaced separate inset-block-start/inline-start and width/height with inset:0 on __control
  • Set position:absolute, margin:0, padding:0 consistently
  • Replaced cursor:pointer with cursor:inherit and cleared background, border, outline on Switch control
src/components/Radio/Radio.scss
src/components/Switch/Switch.scss
src/components/Checkbox/Checkbox.scss
Enhance focus-visible outlines
  • Added outline-offset:1px alongside outline on focus-visible states
src/components/Radio/Radio.scss
src/components/Switch/Switch.scss
src/components/Checkbox/Checkbox.scss
Align ControlLabel layout and restore spacing hack
  • Added align-items:baseline to the label container
  • Set indicator to display:flex with centered content
  • Reintroduced hidden ::after pseudo-element for spacing
src/components/ControlLabel/ControlLabel.scss

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @amje - I've reviewed your changes - here's some feedback:

  • Consider extracting the repeated focus-visible outline and outline-offset logic into a shared mixin to keep the focus styles DRY across Checkbox, Radio, and Switch.
  • Since you've removed explicit cursor: pointer on the __control elements, double-check that the parent container still provides the expected pointer cursor for clickable inputs.
  • After switching ControlLabel to align-items: baseline, please verify multi-line labels or icons still align correctly and no vertical misalignment is introduced.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the repeated focus-visible outline and outline-offset logic into a shared mixin to keep the focus styles DRY across Checkbox, Radio, and Switch.
- Since you've removed explicit cursor: pointer on the __control elements, double-check that the parent container still provides the expected pointer cursor for clickable inputs.
- After switching ControlLabel to align-items: baseline, please verify multi-line labels or icons still align correctly and no vertical misalignment is introduced.

## Individual Comments

### Comment 1
<location> `src/components/Switch/Switch.scss:9` </location>
<code_context>

     &__control {
         position: absolute;
-        inset-block-start: 0;
-        inset-inline-start: 0;
</code_context>

<issue_to_address>
Setting 'cursor: inherit' on __control may not provide the expected pointer cursor for interactive elements.

If the parent doesn't set a pointer cursor, users may not see the expected pointer on hover. Please confirm this matches your intended user experience.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +9 to +17
position: absolute;
inset: 0;
margin: 0;
padding: 0;
opacity: 0;
cursor: pointer;
background: none;
border: none;
outline: none;
cursor: inherit;
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Setting 'cursor: inherit' on __control may not provide the expected pointer cursor for interactive elements.

If the parent doesn't set a pointer cursor, users may not see the expected pointer on hover. Please confirm this matches your intended user experience.

Copy link
Contributor

gravity-ui bot commented Jul 14, 2025

Preview is ready.

Copy link
Contributor

gravity-ui bot commented Jul 14, 2025

Visual Tests Report is ready.

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.

1 participant