Skip to content

refactor(webapp): harden GitLab icon factory with forwardRef, a11y, and tests - #940

Merged
FelixTJDietrich merged 1 commit into
mainfrom
refactor/gitlab-icon-factory-quality
Mar 26, 2026
Merged

refactor(webapp): harden GitLab icon factory with forwardRef, a11y, and tests#940
FelixTJDietrich merged 1 commit into
mainfrom
refactor/gitlab-icon-factory-quality

Conversation

@FelixTJDietrich

@FelixTJDietrich FelixTJDietrich commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

Description

Hardens the createGitLabIcon factory to match the @primer/octicons-react API surface and cleans up dead code. This completes the quality bar for the GitLab visual identity work from the provider abstraction layer.

Changes

gitlab-icons.tsx — Icon factory refactored

  • forwardRef<SVGSVGElement> for DOM ref access
  • Rest-prop spreading (...rest) for native SVG attributes (data-*, style, aria-*)
  • Conditional accessibility: aria-hidden="true" for decorative icons, role="img" + aria-label for labelled icons
  • Exported GitLabIconProps type extending Omit<SVGProps<SVGSVGElement>, "children">
  • focusable="false" always set (prevents IE/Edge focus ring on SVG)

provider-icons.stories.tsx — New Accessibility story

  • Demonstrates decorative vs labelled icon usage patterns
  • Shows icon inside a labelled button (icon stays decorative)

GithubBadge.tsx — Deleted

  • Dead deprecated re-export shim with zero imports

What was NOT changed (deliberate)

  • IconComponent type stays narrow ({size?, className?}) — correct minimal interface for the dispatch layer
  • No <title> element — role="img" + aria-label is sufficient per WAI-ARIA; <title> has inconsistent screen reader support
  • No tanuki logo or pipeline icon — YAGNI, no consumer exists
  • onemphasis/oninverse token naming — currently unused, separate cleanup

How to Test

  • cd webapp && npm run storybook → "Provider/Icons" → verify all 6 stories render correctly, including new "Accessibility" story
  • Verify ref forwarding works: const ref = createRef(); <GitLabMergeRequestIcon ref={ref} />
  • Verify labelled mode: <GitLabMergeRequestIcon aria-label="Open MR" /> renders with role="img", no aria-hidden

Closes #724

@FelixTJDietrich
FelixTJDietrich requested a review from a team as a code owner March 26, 2026 07:13
Copilot AI review requested due to automatic review settings March 26, 2026 07:13
@dosubot dosubot Bot added the enhancement Improvement to existing functionality label Mar 26, 2026
@github-actions github-actions Bot added refactor Code restructuring without changing behavior webapp React app: UI components, routes, state management labels Mar 26, 2026
@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Removed deprecated GithubBadge re-export and refactored GitLab merge request icon components to forward refs, expand SVG prop support via Omit pattern, and conditionally apply accessibility attributes (aria-hidden/role) based on label presence. Added comprehensive test coverage and accessibility documentation story.

Changes

Cohort / File(s) Summary
Deprecated Code Removal
webapp/src/components/shared/GithubBadge.tsx
Removed deprecated GithubBadge re-export module that aliased LabelBadge for backwards compatibility during migration.
GitLab Icon Component Enhancement
webapp/src/lib/provider/gitlab-icons.tsx
Exported GitLabIconProps interface extending Omit<SVGProps<SVGSVGElement>, "children"> to enable full SVG attribute support; added forwardRef to forward ref to root SVG; refactored accessibility handling to conditionally set aria-hidden="true" only when no aria-label/aria-labelledby present and conditionally set role="img" when labelled; now spreads all props onto SVG element.
GitLab Icon Test Suite
webapp/src/lib/provider/gitlab-icons.test.tsx
Added comprehensive Vitest suite covering SVG rendering attributes (viewBox, fill, path rules), size prop behavior with defaults and custom values, conditional accessibility attributes, prop forwarding (className/ref/data-\*/style), displayName verification, icon variants with distinct paths, and draft alias behavior.
GitLab Icon Accessibility Story
webapp/src/lib/provider/provider-icons.stories.tsx
Added Accessibility Storybook story demonstrating three labeling patterns: decorative rendering without aria-label (aria-hidden="true"), non-decorative rendering with aria-label (role="img"), and icon-within-button context where button text supplies accessible name.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit refactored the merge request icons so fine,
Now refs and SVG props align,
With accessibility in mind, conditional and bright,
The GitLab icons shine just right! 🐰✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The PR successfully implements core objectives: exports GitLabIconProps, adds accessibility handling (aria-hidden for decorative, role/aria-label for labelled), forwards refs via forwardRef, adds 16 comprehensive tests, and includes Storybook story. However, icon SVG assets, provider registration in ProviderIcon, and color tokens mentioned in #724 are not addressed in this refactor-focused PR. Clarify whether this PR is a partial implementation (factory hardening) with icon assets/colors/provider mapping deferred to follow-up PRs, or whether those changes should be included here to fully close #724.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main refactoring of the GitLab icon factory with forwardRef, accessibility improvements, and comprehensive test coverage.
Out of Scope Changes check ✅ Passed Changes are narrowly focused on refactoring the icon factory, enhancing accessibility, adding tests, and removing a deprecated shim. All modifications directly support the factory hardening objective; no unrelated changes detected.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/gitlab-icon-factory-quality

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors the GitLab icon factory in the webapp provider layer to align with the @primer/octicons-react component surface (ref forwarding, SVG prop passthrough, conditional a11y), and adds targeted rendering tests plus a Storybook a11y demo; also removes a dead deprecated re-export.

Changes:

  • Refactor createGitLabIcon to use forwardRef, spread native SVG props, and apply conditional aria-hidden/role behavior.
  • Add a new Vitest + Testing Library test suite covering structure, sizing, a11y behavior, prop forwarding, and icon variant differences.
  • Add a Storybook “Accessibility” story demonstrating decorative vs labelled icon usage; delete unused GithubBadge shim.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
webapp/src/lib/provider/gitlab-icons.tsx Harden GitLab icon factory with ref forwarding, SVG prop passthrough, and conditional accessibility attributes.
webapp/src/lib/provider/__tests__/gitlab-icons.test.tsx Adds comprehensive render/a11y/prop-forwarding tests for the GitLab icons.
webapp/src/lib/provider/provider-icons.stories.tsx Adds an Accessibility-focused Storybook example for GitLab icons.
webapp/src/components/shared/GithubBadge.tsx Removes deprecated, unused re-export shim.

…nd tests

- Refactor `createGitLabIcon` to use `forwardRef`, rest-prop spreading,
  and conditional `aria-hidden` / `role="img"` based on labelling props,
  mirroring the `@primer/octicons-react` API surface.
- Export `GitLabIconProps` extending `SVGProps<SVGSVGElement>` for type safety.
- Add Accessibility story demonstrating decorative vs labelled icon usage.
- Delete dead `GithubBadge.tsx` deprecated shim (zero imports).

Closes #724

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@FelixTJDietrich
FelixTJDietrich force-pushed the refactor/gitlab-icon-factory-quality branch from 80da70d to 9c6ba83 Compare March 26, 2026 07:23
@github-actions github-actions Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Mar 26, 2026
@FelixTJDietrich
FelixTJDietrich merged commit ae5d099 into main Mar 26, 2026
41 checks passed
@FelixTJDietrich
FelixTJDietrich deleted the refactor/gitlab-icon-factory-quality branch March 26, 2026 08:12
@github-actions

Copy link
Copy Markdown
Contributor

📚 Documentation Preview

Preview has been removed (PR closed)

@FelixTJDietrich

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 0.52.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@FelixTJDietrich FelixTJDietrich added the released Included in a published release label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality refactor Code restructuring without changing behavior released Included in a published release size:M This PR changes 30-99 lines, ignoring generated files. webapp React app: UI components, routes, state management

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(webapp): GitLab visual identity (icons, colors, badges)

2 participants