Skip to content

fix(react): fix icon rendering in v0.9 basic catalog#1031

Open
ppazosp wants to merge 1 commit intogoogle:mainfrom
ppazosp:fix/946-react-icon-rendering
Open

fix(react): fix icon rendering in v0.9 basic catalog#1031
ppazosp wants to merge 1 commit intogoogle:mainfrom
ppazosp:fix/946-react-icon-rendering

Conversation

@ppazosp
Copy link
Copy Markdown

@ppazosp ppazosp commented Mar 29, 2026

Description

Adds camelCase-to-snake_case conversion for icon names in the React v0.9 Icon component.

The A2UI spec defines icon names in camelCase (e.g., shoppingCart) but Material Symbols Outlined font requires snake_case ligatures (shopping_cart). Without this conversion, multi-word icon names rendered as empty/broken boxes. The fix matches the existing pattern used in Angular v0.9 and React v0.8 renderers.

Fixes #946

Pre-launch Checklist

Add camelCase to snake_case conversion for Material Symbols icon names.
The A2UI spec uses camelCase names (e.g., skipPrevious, shoppingCart)
but Material Symbols Outlined requires snake_case (skip_previous,
shopping_cart). This matches the approach used in the Angular renderer
and React v0_8 renderer.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a toSnakeCase helper function to the Icon component to ensure icon names are correctly formatted for Material Symbols. Feedback was provided to improve the regex implementation to avoid generating leading underscores for capitalized input strings.

* e.g., "shoppingCart" -> "shopping_cart", "skipPrevious" -> "skip_previous"
*/
function toSnakeCase(str: string): string {
return str.replace(/([A-Z])/g, '_$1').toLowerCase();
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.

medium

The current implementation of toSnakeCase will produce a leading underscore for strings that start with an uppercase letter (e.g., 'ShoppingCart' becomes '_shopping_cart'). This is likely not the intended behavior for Material Symbols font ligatures.

A more robust implementation would handle this case correctly. Using a negative lookbehind (?<!^) can prevent matching an uppercase letter at the beginning of the string.

Suggested change
return str.replace(/([A-Z])/g, '_$1').toLowerCase();
return str.replace(/(?<!^)([A-Z])/g, '_$1').toLowerCase();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The A2UI schema enforces camelCase icon names via a Zod enum (ICON_NAMES in basic_components.ts), so PascalCase input is never valid. This regex is also identical to Angular v0.9 (icon.component.ts:98) and React v0.8 (Icon.tsx:29). Changing it here would break consistency across renderers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

[React] Fix icon rendering

1 participant