Skip to content

fix: align Text component icon with title instead of value#4071

Open
leno23 wants to merge 1 commit intoAltinn:mainfrom
leno23:fix/text-component-icon-placement
Open

fix: align Text component icon with title instead of value#4071
leno23 wants to merge 1 commit intoAltinn:mainfrom
leno23:fix/text-component-icon-placement

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented Mar 23, 2026

Description

Related Issue(s)

  • closes #{issue number}

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • New Features

    • Added support for optional label prefix in label components.
  • Refactor

    • Simplified text component interface and restructured icon rendering logic.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

Icon rendering logic is refactored across three text-related components. DisplayText simplifies its prop interface to accept only value and labelId, removing icon-handling code. Label gains optional labelPrefix support for prepending content to titles. TextComponent relocates icon rendering, either wrapping DisplayText with icons in a container or passing them as labelPrefix to Label.

Changes

Cohort / File(s) Summary
DisplayText simplification
src/app-components/Text/DisplayText.tsx
Component prop type narrowed from full TextProps to Pick<TextProps, 'value' | 'labelId'>. Conditional icon rendering (<img> block gated by iconUrl) removed entirely; iconUrl and iconAltText parameters eliminated.
Label prefix support
src/components/label/Label.tsx
New optional prop labelPrefix?: React.ReactNode added to LabelProps. LabelInner threads labelPrefix into label construction, conditionally prepending it before the resolved title text.
TextComponent icon refactoring
src/layout/Text/TextComponent.tsx
Icon rendering precomputed as iconElement. When title is absent, icon and DisplayText wrapped in direction-aware <div>. When title present, icon passed as labelPrefix to label configuration instead of via iconUrl/iconAltText props to DisplayText.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~23 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description contains only the template skeleton with no substantive content filled in—no implementation details, no issue number provided, and no verification checkboxes marked. Fill in the description with details about the changes, complete the Related Issue(s) section with an issue number, and mark the relevant verification/QA checkboxes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: moving the Text component icon alignment from the value to the title.

✏️ 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.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (2)
src/layout/Text/TextComponent.tsx (1)

27-37: Formatting differs from project style (Prettier).

The static analysis tool flagged a formatting inconsistency. This should auto-fix with the project's formatter.

🧹 Proposed fix
     return (
-      <div
-        className={cn(
-          classes.textComponent,
-          direction === 'vertical' ? classes.vertical : classes.horizontal,
-        )}
-      >
+      <div className={cn(classes.textComponent, direction === 'vertical' ? classes.vertical : classes.horizontal)}>
         {iconElement}
         <DisplayText value={value} />
       </div>
     );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/layout/Text/TextComponent.tsx` around lines 27 - 37, The JSX block in
TextComponent (the return rendering DisplayText with iconElement) is
misformatted per the project Prettier rules; run the project's formatter
(Prettier/format command) or apply the repo's formatting settings to
src/layout/Text/TextComponent.tsx so the JSX props and children spacing/line
breaks match the code style (affecting cn(...) className, the ternary for
direction, and the iconElement/DisplayText lines). Ensure TextComponent's return
follows the same formatting convention as other components (preserve symbols:
TextComponent, cn, classes, direction, iconElement, DisplayText, value) and
commit the auto-fixed file.
src/app-components/Text/DisplayText.tsx (1)

5-12: Remove unused iconUrl and iconAltText from TextProps interface.

Since DisplayText now uses Pick<TextProps, 'value' | 'labelId'> and icon rendering has been moved to TextComponent, the iconUrl and iconAltText properties are dead code. Either remove them from the interface or simplify the component signature to use the interface directly without Pick.

♻️ Proposed fix
 interface TextProps {
   value: string;
-  iconUrl?: string;
-  iconAltText?: string;
   labelId?: string;
 }

-export const DisplayText = ({ value, labelId }: Pick<TextProps, 'value' | 'labelId'>) => (
+export const DisplayText = ({ value, labelId }: TextProps) => (
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app-components/Text/DisplayText.tsx` around lines 5 - 12, The TextProps
interface contains unused fields iconUrl and iconAltText while DisplayText only
consumes value and labelId via Pick<TextProps, 'value' | 'labelId'>; remove the
dead properties (iconUrl, iconAltText) from TextProps or alternatively change
DisplayText to accept TextProps directly (DisplayText) so the interface and
usage are consistent—update TextProps and/or the DisplayText signature and any
imports/usages, and ensure TextComponent (which now handles icon rendering)
remains the sole place using iconUrl/iconAltText.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/app-components/Text/DisplayText.tsx`:
- Around line 5-12: The TextProps interface contains unused fields iconUrl and
iconAltText while DisplayText only consumes value and labelId via
Pick<TextProps, 'value' | 'labelId'>; remove the dead properties (iconUrl,
iconAltText) from TextProps or alternatively change DisplayText to accept
TextProps directly (DisplayText) so the interface and usage are
consistent—update TextProps and/or the DisplayText signature and any
imports/usages, and ensure TextComponent (which now handles icon rendering)
remains the sole place using iconUrl/iconAltText.

In `@src/layout/Text/TextComponent.tsx`:
- Around line 27-37: The JSX block in TextComponent (the return rendering
DisplayText with iconElement) is misformatted per the project Prettier rules;
run the project's formatter (Prettier/format command) or apply the repo's
formatting settings to src/layout/Text/TextComponent.tsx so the JSX props and
children spacing/line breaks match the code style (affecting cn(...) className,
the ternary for direction, and the iconElement/DisplayText lines). Ensure
TextComponent's return follows the same formatting convention as other
components (preserve symbols: TextComponent, cn, classes, direction,
iconElement, DisplayText, value) and commit the auto-fixed file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 02a1f6df-922c-46e4-b4d7-315c23199d84

📥 Commits

Reviewing files that changed from the base of the PR and between 0fca32f and 2ac7ad2.

📒 Files selected for processing (3)
  • src/app-components/Text/DisplayText.tsx
  • src/components/label/Label.tsx
  • src/layout/Text/TextComponent.tsx

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