Skip to content

feat(icon): apply rh-standard styling and add opt-out#12320

Open
kmcfaul wants to merge 3 commits intopatternfly:mainfrom
kmcfaul:rh-standard-icon-styling
Open

feat(icon): apply rh-standard styling and add opt-out#12320
kmcfaul wants to merge 3 commits intopatternfly:mainfrom
kmcfaul:rh-standard-icon-styling

Conversation

@kmcfaul
Copy link
Copy Markdown
Contributor

@kmcfaul kmcfaul commented Apr 6, 2026

What: Closes #12321

  • Bumps core version for new class
  • Automatically applies class for all standard icons
  • Adds noStandardSetStyling to opt out of applying the class

Summary by CodeRabbit

  • New Features
    • Icons gain an optional property to opt out of the library's default SVG styling; default styling remains enabled.
  • Tests
    • Added tests verifying default styling, explicit enabling, and opt-out behavior for icon rendering.

@kmcfaul kmcfaul changed the title feat(icon): add rh-standard set classname & opt-out feat(icon): apply rh-standard styling and add opt-out Apr 6, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ff9fb23-aa40-426a-bbde-365a28180929

📥 Commits

Reviewing files that changed from the base of the PR and between 0ffa255 and a5ffaf6.

📒 Files selected for processing (2)
  • packages/react-icons/src/__tests__/createIcon.test.tsx
  • packages/react-icons/src/createIcon.tsx
✅ Files skipped from review due to trivial changes (1)
  • packages/react-icons/src/tests/createIcon.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-icons/src/createIcon.tsx

Walkthrough

Added an optional noDefaultStyle?: boolean prop to icon components and set its default to false. When true, the generated icon component omits appending the configured svgClassName to the SVG element; otherwise behavior is unchanged.

Changes

Cohort / File(s) Summary
Icon factory
packages/react-icons/src/createIcon.tsx
Added noDefaultStyle?: boolean to exported SVGIconProps, added static defaultProps: SVGIconProps = { noDefaultStyle: false }, and updated render logic to skip appending svgClassName when noDefaultStyle is truthy.
Tests
packages/react-icons/src/__tests__/createIcon.test.tsx
Added rhStandardIcon fixture and three tests verifying SVG svgClassName is applied by default, applied when noDefaultStyle={false}, and omitted when noDefaultStyle is truthy.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • wise-king-sullyman
  • thatblindgeye
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(icon): apply rh-standard styling and add opt-out' directly reflects the main changes: applying rh-standard styling to icons and adding an opt-out mechanism via the noDefaultStyle prop.
Linked Issues check ✅ Passed The PR successfully implements both requirements from issue #12321: it applies rh-standard styling to icons by default and provides an opt-out prop (noDefaultStyle) for consumers to disable the styling.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective of applying rh-standard styling with an opt-out mechanism; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit 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

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

@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Apr 6, 2026

Copy link
Copy Markdown

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/react-icons/src/createIcon.tsx (1)

100-114: ⚠️ Potential issue | 🟠 Major

Opt-out is not applied in the dual-render path.

noStandardSetStyling is only respected in the single-icon branch (Lines 107-114). In the dual-render branch (Lines 155-156), createSvg(...) still unconditionally appends svgClassName, so pf-v6-icon-rh-standard can still render even when opt-out is true.

💡 Proposed fix
-const createSvg = (icon: IconDefinition, iconClassName: string) => {
+const createSvg = (icon: IconDefinition, iconClassName: string, noStandardSetStyling = false) => {
   const { xOffset, yOffset, width, height, svgPathData, svgClassName } = icon ?? {};
@@
-  if (svgClassName) {
+  if (svgClassName && !(noStandardSetStyling && svgClassName === 'pf-v6-icon-rh-standard')) {
     classNames.push(svgClassName);
   }
@@
-        if (svgClassName) {
-          if (svgClassName !== 'pf-v6-icon-rh-standard') {
-            classNames.push(svgClassName);
-          } else {
-            if (!noStandardSetStyling) {
-              classNames.push(svgClassName);
-            }
-          }
-        }
+        if (svgClassName && !(noStandardSetStyling && svgClassName === 'pf-v6-icon-rh-standard')) {
+          classNames.push(svgClassName);
+        }
@@
-            {icon && createSvg(icon, 'pf-v6-icon-default')}
-            {rhUiIcon && createSvg(rhUiIcon, 'pf-v6-icon-rh-ui')}
+            {icon && createSvg(icon, 'pf-v6-icon-default', noStandardSetStyling)}
+            {rhUiIcon && createSvg(rhUiIcon, 'pf-v6-icon-rh-ui', noStandardSetStyling)}

Also applies to: 143-157

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react-icons/src/createIcon.tsx` around lines 100 - 114, The
dual-render path is appending svgClassName unconditionally when calling
createSvg, so the opt-out flag noStandardSetStyling isn't respected and
pf-v6-icon-rh-standard can still be applied; update the dual-render branch in
createIcon/createSvg usage to mirror the single-icon logic: when svgClassName is
defined, only push it to the class list if it's not 'pf-v6-icon-rh-standard' or
if noStandardSetStyling is false (i.e., skip adding that specific class when
noStandardSetStyling is true), ensuring the same conditional handling of
svgClassName used for the single-icon branch (referencing svgClassName,
noStandardSetStyling, createSvg, and iconData/rhUiIcon).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/react-icons/src/createIcon.tsx`:
- Around line 100-114: The dual-render path is appending svgClassName
unconditionally when calling createSvg, so the opt-out flag noStandardSetStyling
isn't respected and pf-v6-icon-rh-standard can still be applied; update the
dual-render branch in createIcon/createSvg usage to mirror the single-icon
logic: when svgClassName is defined, only push it to the class list if it's not
'pf-v6-icon-rh-standard' or if noStandardSetStyling is false (i.e., skip adding
that specific class when noStandardSetStyling is true), ensuring the same
conditional handling of svgClassName used for the single-icon branch
(referencing svgClassName, noStandardSetStyling, createSvg, and
iconData/rhUiIcon).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3406e8bd-ce94-4431-9d2e-d539acf6d03d

📥 Commits

Reviewing files that changed from the base of the PR and between a7a847c and 278cbbe.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • packages/react-core/package.json
  • packages/react-docs/package.json
  • packages/react-icons/package.json
  • packages/react-icons/scripts/icons/rhIconsStandard.mjs
  • packages/react-icons/src/createIcon.tsx
  • packages/react-styles/package.json
  • packages/react-tokens/package.json

Copy link
Copy Markdown
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

Can we add some tests to the createIcon test file for this new prop?

@kmcfaul kmcfaul force-pushed the rh-standard-icon-styling branch from 278cbbe to 0ffa255 Compare April 13, 2026 15:28
@kmcfaul
Copy link
Copy Markdown
Contributor Author

kmcfaul commented Apr 13, 2026

@thatblindgeye Updated. I had a thought as I was adding the unit tests though. Do you think we'd want the noStandardSetStyling prop to be more generic like noDefaultSvgStyling and opt out of all bundled svgClassName?

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
packages/react-icons/src/__tests__/createIcon.test.tsx (1)

63-76: Add one regression test to protect non-standard class behavior.

Current additions validate RH standard behavior, but a guard case for non-standard svgClassName with noStandardSetStyling={true} would prevent accidental broadening later.

Suggested test addition
+test('does not affect non-standard svgClassName when noStandardSetStyling is true', () => {
+  render(<SVGIcon noStandardSetStyling />);
+  expect(screen.getByRole('img', { hidden: true })).toHaveClass(singlePathIcon.svgClassName ?? '');
+});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react-icons/src/__tests__/createIcon.test.tsx` around lines 63 - 76,
Add a regression test to ensure a custom svgClassName isn't overridden when
noStandardSetStyling is true: render <RhStandardIcon noStandardSetStyling
svgClassName="my-custom" /> and assert the rendered img (getByRole('img', {
hidden: true })) hasClass('my-custom') and does not
haveClass('pf-v6-icon-rh-standard'); this protects the non-standard class
behavior in the RhStandardIcon component.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/react-icons/src/__tests__/createIcon.test.tsx`:
- Around line 63-76: Add a regression test to ensure a custom svgClassName isn't
overridden when noStandardSetStyling is true: render <RhStandardIcon
noStandardSetStyling svgClassName="my-custom" /> and assert the rendered img
(getByRole('img', { hidden: true })) hasClass('my-custom') and does not
haveClass('pf-v6-icon-rh-standard'); this protects the non-standard class
behavior in the RhStandardIcon component.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 079f5970-a69d-4429-a15f-beb7438d20e1

📥 Commits

Reviewing files that changed from the base of the PR and between 278cbbe and 0ffa255.

📒 Files selected for processing (3)
  • packages/react-icons/scripts/icons/rhIconsStandard.mjs
  • packages/react-icons/src/__tests__/createIcon.test.tsx
  • packages/react-icons/src/createIcon.tsx

@thatblindgeye
Copy link
Copy Markdown
Contributor

Updated. I had a thought as I was adding the unit tests though. Do you think we'd want the noStandardSetStyling prop to be more generic like noDefaultSvgStyling and opt out of all bundled svgClassName?

That would probably be nice, though not a blocker for me.

@kmcfaul
Copy link
Copy Markdown
Contributor Author

kmcfaul commented Apr 14, 2026

@thatblindgeye I did update the prop to be more generic if you don't mind re-reviewing. I figured it simplifies the internal logic a good bit and that way other icons we add that may have default styling have an option to remove it.

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.

Icon - apply rhds standard icon variant

3 participants