Skip to content

fix: follow required marker styling convention - #4533

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
yyhhyyyyyy:fix/required-label-asterisk-color
Apr 29, 2026
Merged

fix: follow required marker styling convention#4533
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
yyhhyyyyyy:fix/required-label-asterisk-color

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

完善必填项*的显示效果

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
未修改:
image
修改后:
image

Summary by CodeRabbit

  • New Features
    • Required field indicators in labels now render a styled asterisk for improved clarity and visibility.
    • Trailing asterisks (with optional preceding space) are automatically detected and transformed without altering surrounding text.
    • Labels with mixed content (plain text plus other elements) preserve structure while still showing the required marker correctly.

@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Label now renders its children inside LabelPrimitive.Root and detects a trailing required-marker (*) to replace that final character with a <span className="text-destructive">*</span>, handling both primitive-only and mixed React children.

Changes

Cohort / File(s) Summary
Label Component
web/default/src/components/ui/label.tsx
Component signature updated to accept children. Renders children within LabelPrimitive.Root. Adds detection for a trailing * (with optional preceding whitespace) and replaces only that final marker with a nested <span className="text-destructive">*</span>. Handles both pure primitive children (joined string/number) and mixed children by transforming only primitive nodes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble code and hop with glee,
A little star now bold to see,
One tiny * in crimson dressed,
The form looks neat — I thump my chest,
Hooray, the label's dressed for tea!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: follow required marker styling convention' accurately describes the main change: restoring red styling for required-field asterisks in the Label component.
Linked Issues check ✅ Passed The PR implementation directly addresses issue #4532 by modifying the Label component to render required-field asterisks with red styling using the 'text-destructive' class, meeting the stated objective.
Out of Scope Changes check ✅ Passed All changes in label.tsx are directly focused on implementing the required-marker detection and red styling, with no unrelated modifications beyond the stated objective.

✏️ 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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/default/src/components/ui/label.tsx`:
- Around line 7-18: The required-marker regex is too narrow (only matches a
single space before '*') so update requiredMarkerPattern and the trimming logic
to accept zero-or-more whitespace (including non-breaking spaces) before the
asterisk; e.g. replace the pattern with /\s*\*$/ and change renderRequiredMarker
to derive the label text by removing that trailing whitespace+asterisk (e.g. via
text.replace(/\s*\*$/, '')) before rendering the visible '*' in a styled span;
keep the function name renderRequiredMarker and the visible span with className
'text-destructive'.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 634eab6b-88b4-45a4-ac6d-ba8ba8ddde98

📥 Commits

Reviewing files that changed from the base of the PR and between e0b6eb3 and 211b354.

📒 Files selected for processing (1)
  • web/default/src/components/ui/label.tsx

Comment on lines +7 to +18
const requiredMarkerPattern = /\s\*$/

function renderRequiredMarker(text: string, key?: React.Key) {
if (!requiredMarkerPattern.test(text)) {
return text
}

return (
<span key={key}>
{text.slice(0, -1)}
<span className='text-destructive'>*</span>
</span>

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.

⚠️ Potential issue | 🟡 Minor

Broaden the required-marker matcher.

/\s\*$/ only catches labels with exactly one whitespace character before *. Labels like Name*, labels using non-breaking spaces, or other formatted variants will still render an unstyled asterisk.

🔧 Suggested fix
-const requiredMarkerPattern = /\s\*$/
+const requiredMarkerPattern = /\s*\*$/

 function renderRequiredMarker(text: string, key?: React.Key) {
   if (!requiredMarkerPattern.test(text)) {
     return text
   }

   return (
     <span key={key}>
-      {text.slice(0, -1)}
+      {text.replace(/\s*\*$/, '')}
       <span className='text-destructive'>*</span>
     </span>
   )
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/default/src/components/ui/label.tsx` around lines 7 - 18, The
required-marker regex is too narrow (only matches a single space before '*') so
update requiredMarkerPattern and the trimming logic to accept zero-or-more
whitespace (including non-breaking spaces) before the asterisk; e.g. replace the
pattern with /\s*\*$/ and change renderRequiredMarker to derive the label text
by removing that trailing whitespace+asterisk (e.g. via text.replace(/\s*\*$/,
'')) before rendering the visible '*' in a styled span; keep the function name
renderRequiredMarker and the visible span with className 'text-destructive'.

@yyhhyyyyyy

Copy link
Copy Markdown
Contributor Author

@t0ng7u 麻烦 review 一下,thanks

@Calcium-Ion

Copy link
Copy Markdown
Member

可以的话弄一下gpg签名

@yyhhyyyyyy
yyhhyyyyyy force-pushed the fix/required-label-asterisk-color branch from 211b354 to aee22a4 Compare April 29, 2026 07:41
@yyhhyyyyyy

Copy link
Copy Markdown
Contributor Author

可以的话弄一下gpg签名

已签名

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

♻️ Duplicate comments (1)
web/default/src/components/ui/label.tsx (1)

7-17: ⚠️ Potential issue | 🟡 Minor

Required-marker regex is still too narrow

The matcher still only catches labels with exactly one whitespace before *. That leaves no-space variants (e.g. Name*) unstyled.

Suggested fix
-const requiredMarkerPattern = /\s\*$/
+const requiredMarkerPattern = /\s*\*$/

 function renderRequiredMarker(text: string, key?: React.Key) {
   if (!requiredMarkerPattern.test(text)) {
     return text
   }

   return (
     <span key={key}>
-      {text.slice(0, -1)}
+      {text.replace(/\s*\*$/, '')}
       <span className='text-destructive'>*</span>
     </span>
   )
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/default/src/components/ui/label.tsx` around lines 7 - 17, The
required-marker regex only matches labels with one space before the star; update
requiredMarkerPattern to allow zero or more spaces (e.g. /\s*\*$/) and in
renderRequiredMarker use that pattern to strip the trailing star and any
surrounding whitespace (e.g. derive labelText =
text.replace(requiredMarkerPattern, '') instead of text.slice(0, -1)) so labels
like "Name*" and "Name *" both render with the styled asterisk; reference:
requiredMarkerPattern and renderRequiredMarker.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@web/default/src/components/ui/label.tsx`:
- Around line 7-17: The required-marker regex only matches labels with one space
before the star; update requiredMarkerPattern to allow zero or more spaces (e.g.
/\s*\*$/) and in renderRequiredMarker use that pattern to strip the trailing
star and any surrounding whitespace (e.g. derive labelText =
text.replace(requiredMarkerPattern, '') instead of text.slice(0, -1)) so labels
like "Name*" and "Name *" both render with the styled asterisk; reference:
requiredMarkerPattern and renderRequiredMarker.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bb263d90-bb91-4961-ad5b-1a561085d69c

📥 Commits

Reviewing files that changed from the base of the PR and between 211b354 and aee22a4.

📒 Files selected for processing (1)
  • web/default/src/components/ui/label.tsx

@Calcium-Ion
Calcium-Ion merged commit d393172 into QuantumNous:main Apr 29, 2026
1 check passed
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.

v1.0.0-alpha.1 新版本 UI 的必填项 * 不再以红色显著提示

2 participants