Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/packages/form/demos/h5/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const Demo2 = () => {
<Form
divider
labelPosition="left"
starPosition="right"
onFinish={(values) => submitSucceed(values)}
onFinishFailed={(values, errors) => submitFailed(errors)}
footer={
Expand Down
1 change: 1 addition & 0 deletions src/packages/form/demos/taro/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const Demo2 = () => {
<Form
divider
labelPosition="left"
starPosition="right"
onFinish={(values) => submitSucceed(values)}
onFinishFailed={(values, errors) => submitFailed(errors)}
footer={
Expand Down
27 changes: 13 additions & 14 deletions src/packages/formitem/formitem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
word-wrap: break-word;
text-align: $form-item-label-text-align;
line-height: unset;
}

&-label-required {
color: $form-item-required-color;
margin-right: $form-item-required-margin-right;
display: block;
position: absolute;
left: -10px;
&-left-required {
color: $form-item-required-color;
margin-right: $form-item-required-margin-right;
position: absolute;
left: -10px;
}

&-right-required {
color: $form-item-required-color;
margin-left: $form-item-required-margin-right;
position: absolute;
right: -10px;
}
Comment on lines +22 to +34
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

样式拆分合理,但定位方式需要优化

将必填星号样式拆分为左右两个类是正确的做法。但使用固定像素值进行绝对定位可能在不同字体大小或布局下出现对齐问题。

建议考虑使用相对单位或基于字体大小的定位方式:

    &-left-required {
      color: $form-item-required-color;
      margin-right: $form-item-required-margin-right;
-     position: absolute;
-     left: -10px;
+     position: absolute;
+     left: -0.6em;
    }

    &-right-required {
      color: $form-item-required-color;
      margin-left: $form-item-required-margin-right;
-     position: absolute;
-     right: -10px;
+     position: absolute;
+     right: -0.6em;
    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
&-left-required {
color: $form-item-required-color;
margin-right: $form-item-required-margin-right;
position: absolute;
left: -10px;
}
&-right-required {
color: $form-item-required-color;
margin-left: $form-item-required-margin-right;
position: absolute;
right: -10px;
}
&-left-required {
color: $form-item-required-color;
margin-right: $form-item-required-margin-right;
position: absolute;
left: -0.6em;
}
&-right-required {
color: $form-item-required-color;
margin-left: $form-item-required-margin-right;
position: absolute;
right: -0.6em;
}
🤖 Prompt for AI Agents
In src/packages/formitem/formitem.scss between lines 22 and 34, the absolute
positioning of the required star uses fixed pixel values which can cause
alignment issues with different font sizes or layouts. Replace the fixed pixel
values for left and right positioning with relative units such as em or rem
based on the font size to ensure consistent alignment across various contexts.

}

.nut-form-item-labeltxt {
Expand Down Expand Up @@ -136,13 +142,6 @@
white-space: nowrap;
}

.nut-form-item-label-left-required {
display: block;
line-height: 1.5;
position: absolute;
left: 0.1em;
}

.nut-form-item-top {
flex-direction: column;
align-items: flex-start;
Expand Down
6 changes: 4 additions & 2 deletions src/packages/formitem/formitem.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,17 @@ export class FormItem extends React.Component<

const { starPosition } = this.context.formInstance
const renderStar = (required || requiredInRules) && (
<Text className="nut-form-item-label-required required">*</Text>
<Text className={`nut-form-item-label-${starPosition}-required required`}>
*
</Text>
)
const renderLabel = (
<>
<Text className="nut-form-item-labeltxt">
{starPosition === 'left' ? renderStar : null}
{label}
{starPosition === 'right' ? renderStar : null}
</Text>
{starPosition === 'right' ? renderStar : null}
</>
)
return (
Expand Down
6 changes: 4 additions & 2 deletions src/packages/formitem/formitem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,17 @@ export class FormItem extends React.Component<

const { starPosition } = this.context.formInstance
const renderStar = (required || requiredInRules) && (
<div className="nut-form-item-label-required required">*</div>
<span className={`nut-form-item-label-${starPosition}-required required`}>
*
</span>
)
const renderLabel = (
<>
<span className="nut-form-item-labeltxt">
{starPosition === 'left' ? renderStar : null}
{label}
{starPosition === 'right' ? renderStar : null}
</span>
{starPosition === 'right' ? renderStar : null}
</>
)
return (
Expand Down
Loading